Merge branch 'virtual-scrolling-2.0' into shigusegubu-themes3
This commit is contained in:
commit
e22eba8806
3 changed files with 37 additions and 46 deletions
|
|
@ -102,7 +102,6 @@ export default {
|
||||||
// # Main things
|
// # Main things
|
||||||
const {
|
const {
|
||||||
focusedId,
|
focusedId,
|
||||||
focusedIdRaw,
|
|
||||||
conversationId,
|
conversationId,
|
||||||
setFocused,
|
setFocused,
|
||||||
currentStatus,
|
currentStatus,
|
||||||
|
|
@ -321,8 +320,8 @@ export default {
|
||||||
}
|
}
|
||||||
const diveIntoStatus = (id) => scrollTo(new Set([id]))
|
const diveIntoStatus = (id) => scrollTo(new Set([id]))
|
||||||
const diveToTopLevel = () => scrollTo(new Set([currentAncestors.value[0].id]))
|
const diveToTopLevel = () => scrollTo(new Set([currentAncestors.value[0].id]))
|
||||||
watch(focusedIdRaw, async (neu) => {
|
|
||||||
if (!isPage.value) return
|
watch(focusedId, async (neu, old) => {
|
||||||
if (neu) scrollTo(new Set([neu]))
|
if (neu) scrollTo(new Set([neu]))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { computed, provide, ref, watch } from 'vue'
|
import { computed, provide, ref, watch, nextTick } from 'vue'
|
||||||
|
|
||||||
import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
||||||
import { useOAuthStore } from 'src/stores/oauth.js'
|
import { useOAuthStore } from 'src/stores/oauth.js'
|
||||||
|
|
@ -28,49 +28,12 @@ export function useConversation(statusId, expanded) {
|
||||||
mastoUserSocketStatus === WSConnectionStatus.JOINED,
|
mastoUserSocketStatus === WSConnectionStatus.JOINED,
|
||||||
)
|
)
|
||||||
|
|
||||||
// # Focus
|
|
||||||
const focused = ref(null)
|
|
||||||
const { mainStatus: focusedStatus } = useMainStatus(focused)
|
|
||||||
const setFocused = (id) => {
|
|
||||||
focused.value = id
|
|
||||||
}
|
|
||||||
watch(mainStatusId, (val) => setFocused(val))
|
|
||||||
const focusedId = computed(() => expanded.value ? focusedStatus.value?.id : null)
|
|
||||||
provide('focusedId', focusedId)
|
|
||||||
|
|
||||||
watch(statusId, (neu, old) => {
|
|
||||||
if (neu) setFocused(neu)
|
|
||||||
}, { immediate: true })
|
|
||||||
|
|
||||||
watch(statusId, (neu, old) => {
|
watch(statusId, (neu, old) => {
|
||||||
if (neu !== old) {
|
if (neu !== old) {
|
||||||
fetchConversation()
|
fetchConversation()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(
|
|
||||||
expanded,
|
|
||||||
(value) => {
|
|
||||||
setFocused(value ? mainStatusId.value : null)
|
|
||||||
},
|
|
||||||
{ immediate: true },
|
|
||||||
)
|
|
||||||
|
|
||||||
watch(
|
|
||||||
focusedStatus,
|
|
||||||
(newVal, oldVal) => {
|
|
||||||
if (!newVal) return
|
|
||||||
if (newVal?.id === oldVal?.id) return // prevents infinite loop
|
|
||||||
if (!streamingEnabled.value) {
|
|
||||||
useStatusesStore().fetchStatus(newVal.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
useStatusesStore().fetchFavsAndRepeats(newVal.id)
|
|
||||||
useStatusesStore().fetchEmojiReactions(newVal.id)
|
|
||||||
},
|
|
||||||
{ immediate: true },
|
|
||||||
)
|
|
||||||
|
|
||||||
const sortById = (a, b) => {
|
const sortById = (a, b) => {
|
||||||
const idA = a.type === 'retweet' ? a.retweeted_status.id : a.id
|
const idA = a.type === 'retweet' ? a.retweeted_status.id : a.id
|
||||||
const idB = b.type === 'retweet' ? b.retweeted_status.id : b.id
|
const idB = b.type === 'retweet' ? b.retweeted_status.id : b.id
|
||||||
|
|
@ -89,9 +52,13 @@ export function useConversation(statusId, expanded) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const fullConversation = ref(new Set([currentStatus.value?.id].filter(Boolean)))
|
const fullConversation = ref(new Set([currentStatus.value?.id].filter(Boolean)))
|
||||||
|
const fullyLoaded = ref(false)
|
||||||
const conversationId = computed(
|
const conversationId = computed(
|
||||||
() => mainStatus.value?.statusnet_conversation_id,
|
() => mainStatus.value?.statusnet_conversation_id,
|
||||||
)
|
)
|
||||||
|
watch(conversationId, (neu, old) => {
|
||||||
|
if (neu !== old) fullyLoaded.value = false
|
||||||
|
})
|
||||||
const conversation = computed(() => {
|
const conversation = computed(() => {
|
||||||
if (!currentStatus.value) {
|
if (!currentStatus.value) {
|
||||||
return []
|
return []
|
||||||
|
|
@ -101,13 +68,12 @@ export function useConversation(statusId, expanded) {
|
||||||
return [currentStatus.value]
|
return [currentStatus.value]
|
||||||
}
|
}
|
||||||
|
|
||||||
const conversation = fullConversation.value
|
return [...fullConversation.value.keys()]
|
||||||
|
|
||||||
return [...conversation.keys()]
|
|
||||||
.map((k) => useStatusesStore().allStatuses.get(k))
|
.map((k) => useStatusesStore().allStatuses.get(k))
|
||||||
.filter((status) => status.type != 'repeat') // Old backend behavior?
|
.filter((status) => status.type != 'repeat') // Old backend behavior?
|
||||||
.toSorted(sortById)
|
.toSorted(sortById)
|
||||||
})
|
})
|
||||||
|
|
||||||
const replies = computed(() =>
|
const replies = computed(() =>
|
||||||
conversation.value.reduce(
|
conversation.value.reduce(
|
||||||
(result, { id, in_reply_to_status_id: irid }, index) => {
|
(result, { id, in_reply_to_status_id: irid }, index) => {
|
||||||
|
|
@ -151,6 +117,8 @@ export function useConversation(statusId, expanded) {
|
||||||
...descendants
|
...descendants
|
||||||
].map(({ id }) => id))
|
].map(({ id }) => id))
|
||||||
|
|
||||||
|
await nextTick()
|
||||||
|
fullyLoaded.value = true
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
loadError.value = null
|
loadError.value = null
|
||||||
|
|
@ -172,9 +140,34 @@ export function useConversation(statusId, expanded) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// # Focus
|
||||||
|
const focused = ref(null)
|
||||||
|
const { mainStatus: focusedStatus } = useMainStatus(focused)
|
||||||
|
const setFocused = (id) => {
|
||||||
|
focused.value = id
|
||||||
|
}
|
||||||
|
watch(statusId, (val) => setFocused(val), { immediate: true })
|
||||||
|
|
||||||
|
const focusedId = computed(() => (expanded.value && fullyLoaded.value) ? focusedStatus.value?.id : null)
|
||||||
|
provide('focusedId', focusedId)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
focusedStatus,
|
||||||
|
(newVal, oldVal) => {
|
||||||
|
if (!newVal) return
|
||||||
|
if (newVal?.id === oldVal?.id) return // prevents infinite loop
|
||||||
|
if (!streamingEnabled.value) {
|
||||||
|
useStatusesStore().fetchStatus(newVal.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
useStatusesStore().fetchFavsAndRepeats(newVal.id)
|
||||||
|
useStatusesStore().fetchEmojiReactions(newVal.id)
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
focusedId,
|
focusedId,
|
||||||
focusedIdRaw: focused,
|
|
||||||
conversationId,
|
conversationId,
|
||||||
setFocused,
|
setFocused,
|
||||||
currentStatus,
|
currentStatus,
|
||||||
|
|
|
||||||
|
|
@ -297,7 +297,6 @@ export function useVirtualScrolling({
|
||||||
const elementMiddle = element.top + element.height / 2
|
const elementMiddle = element.top + element.height / 2
|
||||||
const desiredTopBoundary = Math.min(element.top, elementMiddle - (windowHeight.value - offset.value) / 2)
|
const desiredTopBoundary = Math.min(element.top, elementMiddle - (windowHeight.value - offset.value) / 2)
|
||||||
|
|
||||||
console.log(element, desiredTopBoundary, topScrollBoundary.value)
|
|
||||||
scrollBy(0, desiredTopBoundary - topScrollBoundary.value)
|
scrollBy(0, desiredTopBoundary - topScrollBoundary.value)
|
||||||
|
|
||||||
resumeWatchers()
|
resumeWatchers()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue