forked from AkkomaGang/akkoma-fe
chats work and look a bit better
This commit is contained in:
parent
e7ac0e5d68
commit
cfa8edf2c0
4 changed files with 15 additions and 13 deletions
|
@ -494,7 +494,7 @@ i[class*=icon-],
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
z-index: 2;
|
z-index: 100;
|
||||||
box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.6);
|
box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.6);
|
||||||
box-shadow: var(--panelShadow);
|
box-shadow: var(--panelShadow);
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
|
|
@ -19,6 +19,8 @@ library.add(
|
||||||
faChevronLeft
|
faChevronLeft
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const scroller = () => document.getElementById('content')
|
||||||
|
|
||||||
const BOTTOMED_OUT_OFFSET = 10
|
const BOTTOMED_OUT_OFFSET = 10
|
||||||
const JUMP_TO_BOTTOM_BUTTON_VISIBILITY_OFFSET = 10
|
const JUMP_TO_BOTTOM_BUTTON_VISIBILITY_OFFSET = 10
|
||||||
const SAFE_RESIZE_TIME_OFFSET = 100
|
const SAFE_RESIZE_TIME_OFFSET = 100
|
||||||
|
@ -46,7 +48,7 @@ const Chat = {
|
||||||
window.addEventListener('resize', this.handleLayoutChange)
|
window.addEventListener('resize', this.handleLayoutChange)
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
window.addEventListener('scroll', this.handleScroll)
|
scroller().addEventListener('scroll', this.handleScroll)
|
||||||
if (typeof document.hidden !== 'undefined') {
|
if (typeof document.hidden !== 'undefined') {
|
||||||
document.addEventListener('visibilitychange', this.handleVisibilityChange, false)
|
document.addEventListener('visibilitychange', this.handleVisibilityChange, false)
|
||||||
}
|
}
|
||||||
|
@ -57,7 +59,7 @@ const Chat = {
|
||||||
this.setChatLayout()
|
this.setChatLayout()
|
||||||
},
|
},
|
||||||
unmounted () {
|
unmounted () {
|
||||||
window.removeEventListener('scroll', this.handleScroll)
|
scroller().removeEventListener('scroll', this.handleScroll)
|
||||||
window.removeEventListener('resize', this.handleLayoutChange)
|
window.removeEventListener('resize', this.handleLayoutChange)
|
||||||
this.unsetChatLayout()
|
this.unsetChatLayout()
|
||||||
if (typeof document.hidden !== 'undefined') document.removeEventListener('visibilitychange', this.handleVisibilityChange, false)
|
if (typeof document.hidden !== 'undefined') document.removeEventListener('visibilitychange', this.handleVisibilityChange, false)
|
||||||
|
@ -177,13 +179,13 @@ const Chat = {
|
||||||
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
const { offsetHeight = undefined } = this.lastScrollPosition
|
const { offsetHeight = undefined } = this.lastScrollPosition
|
||||||
this.lastScrollPosition = getScrollPosition(document.getElementById('content'))
|
this.lastScrollPosition = getScrollPosition(scroller())
|
||||||
|
|
||||||
const diff = this.lastScrollPosition.offsetHeight - offsetHeight
|
const diff = this.lastScrollPosition.offsetHeight - offsetHeight
|
||||||
if (diff < 0 || (!this.bottomedOut() && expand)) {
|
if (diff < 0 || (!this.bottomedOut() && expand)) {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
document.getElementById('content').scrollTo({
|
scroller().scrollTo({
|
||||||
top: document.getElementById('content').scrollTop - diff,
|
top: scroller().scrollTop - diff,
|
||||||
left: 0
|
left: 0
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -192,7 +194,7 @@ const Chat = {
|
||||||
},
|
},
|
||||||
scrollDown (options = {}) {
|
scrollDown (options = {}) {
|
||||||
const { behavior = 'auto', forceRead = false } = options
|
const { behavior = 'auto', forceRead = false } = options
|
||||||
const scrollable = document.getElementById('content')
|
const scrollable = scroller()
|
||||||
if (!scrollable) { return }
|
if (!scrollable) { return }
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
scrollable.scrollTo({ top: scrollable.scrollHeight, left: 0, behavior })
|
scrollable.scrollTo({ top: scrollable.scrollHeight, left: 0, behavior })
|
||||||
|
@ -211,10 +213,10 @@ const Chat = {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
bottomedOut (offset) {
|
bottomedOut (offset) {
|
||||||
return isBottomedOut(document.getElementById('content'), offset)
|
return isBottomedOut(scroller(), offset)
|
||||||
},
|
},
|
||||||
reachedTop () {
|
reachedTop () {
|
||||||
const scrollable = document.getElementById('content')
|
const scrollable = scroller()
|
||||||
return scrollable && scrollable.scrollTop <= 0
|
return scrollable && scrollable.scrollTop <= 0
|
||||||
},
|
},
|
||||||
cullOlderCheck () {
|
cullOlderCheck () {
|
||||||
|
@ -246,8 +248,8 @@ const Chat = {
|
||||||
}
|
}
|
||||||
}, 200),
|
}, 200),
|
||||||
handleScrollUp (positionBeforeLoading) {
|
handleScrollUp (positionBeforeLoading) {
|
||||||
const positionAfterLoading = getScrollPosition(document.getElementById('content'))
|
const positionAfterLoading = getScrollPosition(scroller())
|
||||||
this.$refs.scrollable.scrollTo({
|
scroller().scrollTo({
|
||||||
top: getNewTopPosition(positionBeforeLoading, positionAfterLoading),
|
top: getNewTopPosition(positionBeforeLoading, positionAfterLoading),
|
||||||
left: 0
|
left: 0
|
||||||
})
|
})
|
||||||
|
@ -268,7 +270,7 @@ const Chat = {
|
||||||
chatService.clear(chatMessageService)
|
chatService.clear(chatMessageService)
|
||||||
}
|
}
|
||||||
|
|
||||||
const positionBeforeUpdate = getScrollPosition(document.getElementById('content'))
|
const positionBeforeUpdate = getScrollPosition(scroller())
|
||||||
this.$store.dispatch('addChatMessages', { chatId, messages }).then(() => {
|
this.$store.dispatch('addChatMessages', { chatId, messages }).then(() => {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
if (fetchOlderMessages) {
|
if (fetchOlderMessages) {
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
background-color: $fallback--bg;
|
background-color: $fallback--bg;
|
||||||
background-color: var(--bg, $fallback--bg);
|
background-color: var(--bg, $fallback--bg);
|
||||||
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-view-heading {
|
.chat-view-heading {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// Captures a scroll position
|
// Captures a scroll position
|
||||||
export const getScrollPosition = (el) => {
|
export const getScrollPosition = (el) => {
|
||||||
console.log(el)
|
|
||||||
return {
|
return {
|
||||||
scrollTop: el.scrollTop,
|
scrollTop: el.scrollTop,
|
||||||
scrollHeight: el.scrollHeight,
|
scrollHeight: el.scrollHeight,
|
||||||
|
|
Loading…
Reference in a new issue