diff --git a/src/components/conversation/conversation.js b/src/components/conversation/conversation.js index ac5f4c77c..e707008d1 100644 --- a/src/components/conversation/conversation.js +++ b/src/components/conversation/conversation.js @@ -1,6 +1,14 @@ import { get } from 'lodash-es' import { storeToRefs } from 'pinia' -import { computed, provide, ref, toRefs, useTemplateRef, watch } from 'vue' +import { + computed, + nextTick, + provide, + ref, + toRefs, + useTemplateRef, + watch, +} from 'vue' import { useRouter } from 'vue-router' import ChatMessageList from 'src/components/chat_message_list/chat_message_list.vue' @@ -16,9 +24,9 @@ import { useStatusesStore } from 'src/stores/statuses.js' import { useStreamingStore } from 'src/stores/streaming.js' import { useConversation } from 'src/composables/useConversation.js' -import { useScrollPosition } from 'src/composables/useScrollPosition.js' import { useTreeConversationTopology } from 'src/composables/useTreeConversationTopology.js' import { useVirtualScrolling } from 'src/composables/useVirtualScrolling.js' +import { useScrollPosition } from 'src/composables/useScrollPosition.js' import { WSConnectionStatus } from 'src/api/websocket.js' @@ -139,19 +147,15 @@ export default { loadError, } = useConversation(focusedId, isExpanded) - watch( - expanded, - async (value) => { - if (value) { - await fetchConversation() - } else { - resetDisplayState() - } - if (isPage.value) return - await tryScrollTo(currentStatus.value.id) - }, - { flush: 'post' }, - ) + watch(expanded, async (value) => { + if (value) { + await fetchConversation() + } else { + resetDisplayState() + } + if (isPage.value) return + await tryScrollTo(currentStatus.value.id) + }, { flush: 'post' }) const resetDisplayState = () => { setFocused(statusId.value) @@ -190,20 +194,12 @@ export default { // # Linear style stuff const isLinearView = computed(() => displayStyle.value !== 'tree') const linearElement = useTemplateRef('linear') - const linearScrollCompensation = computed( - () => isLinearView.value && isExpanded.value, - ) + const linearScrollCompensation = computed(() => isLinearView.value && isExpanded.value) const { heightChart: heightChartLinear, changeSuspendState: changeSuspendStateLinear, updateVirtualHeight: updateVirtualHeightLinear, - } = useVirtualScrolling( - conversation, - linearElement, - scroller, - linearScrollCompensation, - currentStatus, - ) + } = useVirtualScrolling(conversation, linearElement, scroller, linearScrollCompensation, currentStatus) // # Tree style stuff const isTreeView = computed(() => displayStyle.value === 'tree') @@ -217,24 +213,18 @@ export default { provide('threadDisplay', threadDisplay) const ancestorsElement = useTemplateRef('ancestors') - const treeScrollCompensation = computed( - () => isTreeView.value && isExpanded.value, - ) + const treeScrollCompensation = computed(() => isTreeView.value && isExpanded.value) const { heightChart: heightChartAncestors, changeSuspendState: changeSuspendStateAncestors, updateVirtualHeight: updateVirtualHeightAncestors, - } = useVirtualScrolling( - currentAncestors, - ancestorsElement, - scroller, - treeScrollCompensation, - ) + } = useVirtualScrolling(currentAncestors, ancestorsElement, scroller, treeScrollCompensation) const currentLevel = computed(() => [currentStatus.value].filter(Boolean)) const currentLevelElement = useTemplateRef('currentLevel') const { heightChart: heightChartCurrentLevel, + totalHeight: totalHeightCurrentLevel, changeSuspendState: changeSuspendStateCurrentLevel, updateVirtualHeight: updateVirtualHeightCurrentLevel, } = useVirtualScrolling(currentLevel, currentLevelElement, scroller, false) diff --git a/src/components/status/status.js b/src/components/status/status.js index 611347b05..7b4649b6a 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -149,10 +149,7 @@ const Status = { computed: { rootClasses() { return [ - { - '-focused': this.focused, - '-conversation': !this.isPage && this.isExpanded, - }, + {'-focused': this.focused, '-conversation': !this.isPage && this.isExpanded }, `-conversation-rank-${this.conversationRank}`, ] }, diff --git a/src/composables/useScrollPosition.js b/src/composables/useScrollPosition.js index f1d6356d9..662a9d355 100644 --- a/src/composables/useScrollPosition.js +++ b/src/composables/useScrollPosition.js @@ -1,4 +1,4 @@ -import { onMounted, onUnmounted, ref } from 'vue' +import { onMounted, onUnmounted, ref, nextTick } from 'vue' export function useScrollPosition() { const x = ref(0) diff --git a/src/composables/useVirtualScrolling.js b/src/composables/useVirtualScrolling.js index 679f418d9..1568b0a41 100644 --- a/src/composables/useVirtualScrolling.js +++ b/src/composables/useVirtualScrolling.js @@ -1,5 +1,5 @@ import { storeToRefs } from 'pinia' -import { computed, ref, toValue, watch } from 'vue' +import { computed, ref, watch, nextTick, toValue } from 'vue' import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useStatusesStore } from 'src/stores/statuses.js' @@ -133,10 +133,9 @@ export function useVirtualScrolling( if (!toValue(scrollCompensation)) return if (scrollInProgress.value) return pauseWatchers() - const getAnchoredEl = (list) => - anchor.value - ? list.find(({ id }) => id === anchor.value) - : list[list.length - 1] + const getAnchoredEl = (list) => anchor.value + ? list.find(({ id }) => id === anchor.value) + : list[list.length - 1] const oldElement = getAnchoredEl(oldVal) const newElement = getAnchoredEl(newVal) const oldOffset = oldElement?.top ?? 0 @@ -170,10 +169,7 @@ export function useVirtualScrolling( const isAboveBottomBoundary = itemTopBoundary < finalBottomScrollBoundary // This accounts for the case where item's boundaries exceed scroll boundary - return { - ...heightChartItem, - visible: isBelowTopBoundary && isAboveBottomBoundary, - } + return { ...heightChartItem, visible: isBelowTopBoundary && isAboveBottomBoundary } }) // Group invisible statuses into spacers