feat: connected replies in home (#572)
This commit is contained in:
parent
1c61aef83b
commit
4f3a065927
4 changed files with 48 additions and 10 deletions
|
@ -1,12 +1,29 @@
|
|||
<script setup lang="ts">
|
||||
import type { Status } from 'masto'
|
||||
const paginator = useMasto().timelines.iterateHome()
|
||||
const stream = await useMasto().stream.streamUser()
|
||||
onBeforeUnmount(() => stream.disconnect())
|
||||
|
||||
const maxDistance = 10
|
||||
function preprocess(items: Status[]) {
|
||||
const newItems = [...items]
|
||||
// TODO: Basic reordering, we should get something more efficient and robust
|
||||
for (let i = items.length - 1; i > 0; i--) {
|
||||
for (let k = 1; k <= maxDistance && i - k >= 0; k++) {
|
||||
if (newItems[i - k].inReplyToId === newItems[i].id) {
|
||||
const item = newItems.splice(i, 1)[0]
|
||||
newItems.splice(i - k, 0, item)
|
||||
k = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
return newItems
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PublishWidget draft-key="home" border="b base" />
|
||||
<TimelinePaginator v-bind="{ paginator, stream }" context="home" />
|
||||
<TimelinePaginator v-bind="{ paginator, stream, preprocess }" context="home" />
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
@ -8,26 +8,37 @@ const { paginator, stream } = defineProps<{
|
|||
paginator: Paginator<any, Status[]>
|
||||
stream?: WsEvents
|
||||
context?: FilterContext
|
||||
preprocess?: (items: any[]) => any[]
|
||||
}>()
|
||||
|
||||
const virtualScroller = $(computedEager(() => useFeatureFlags().experimentalVirtualScroll))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<CommonPaginator v-bind="{ paginator, stream }" :virtual-scroller="virtualScroller">
|
||||
<CommonPaginator v-bind="{ paginator, stream, preprocess }" :virtual-scroller="virtualScroller">
|
||||
<template #updater="{ number, update }">
|
||||
<button py-4 border="b base" flex="~ col" p-3 w-full text-primary font-bold @click="update">
|
||||
{{ $t('timeline.show_new_items', number) }}
|
||||
</button>
|
||||
</template>
|
||||
<template #default="{ item, active }">
|
||||
<template #default="{ item, older, newer, active }">
|
||||
<template v-if="virtualScroller">
|
||||
<DynamicScrollerItem :item="item" :active="active" tag="article">
|
||||
<StatusCard :status="item" border="b base" :context="context" />
|
||||
<StatusCard
|
||||
:status="item" :context="context"
|
||||
:connect-reply="item.id === older?.inReplyToId"
|
||||
:show-reply-to="!(item.inReplyToId && item.inReplyToId === newer?.id)"
|
||||
:class="{ 'border-t border-base': !(item.inReplyToId && item.inReplyToId === newer?.id) }"
|
||||
/>
|
||||
</DynamicScrollerItem>
|
||||
</template>
|
||||
<template v-else>
|
||||
<StatusCard :status="item" border="b base" :context="context" />
|
||||
<StatusCard
|
||||
:status="item" :context="context"
|
||||
:connect-reply="item.id === older?.inReplyToId"
|
||||
:show-reply-to="!(item.inReplyToId && item.inReplyToId === newer?.id)"
|
||||
:class="{ 'border-t border-base': !(item.inReplyToId && item.inReplyToId === newer?.id) }"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
<template #loading>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue