1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-20 07:49:57 +00:00
elk/components/timeline/TimelineHome.vue

30 lines
859 B
Vue
Raw Normal View History

<script setup lang="ts">
2022-12-27 17:47:05 +00:00
import type { Status } from 'masto'
const paginator = useMasto().timelines.iterateHome()
const stream = await useMasto().stream.streamUser()
onBeforeUnmount(() => stream.disconnect())
2022-12-27 17:47:05 +00:00
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>
2022-12-27 18:16:45 +00:00
<PublishWidget draft-key="home" />
2022-12-27 17:47:05 +00:00
<TimelinePaginator v-bind="{ paginator, stream, preprocess }" context="home" />
</div>
</template>