pinafore/routes/_components/timeline/Timeline.html

68 lines
2.2 KiB
HTML

<div class="timeline" role="feed" aria-label="{{label}}">
<VirtualList component="{{StatusListItem}}"
:makeProps
items="{{$statusIds}}"
on:scrollToBottom="onScrollToBottom()"
shown="{{$initialized}}"
footerComponent="{{LoadingFooter}}"
showFooter="{{$initialized && $runningUpdate}}"
realm="{{$currentInstance + '/' + timeline}}"
on:initializedVisibleItems="initialize()"
/>
</div>
<style>
.timeline {
min-height: 60vh;
}
</style>
<script>
import { store } from '../../_utils/store'
import StatusListItem from './StatusListItem.html'
import LoadingFooter from './LoadingFooter.html'
import VirtualList from '../virtualList/VirtualList.html'
import { timelines } from '../../_static/timelines'
import { database } from '../../_utils/database/database'
import { initializeTimeline, fetchStatusesOnScrollToBottom, setupTimeline } from '../../_actions/timeline'
export default {
async oncreate() {
setupTimeline()
},
data: () => ({
StatusListItem: StatusListItem,
LoadingFooter: LoadingFooter
}),
computed: {
makeProps: ($currentInstance) => (statusId) => database.getStatus($currentInstance, statusId),
label: (timeline, $currentInstance) => {
if (timelines[timeline]) {
`${timelines[timeline].label} timeline for ${$currentInstance}`
} else if (timeline.startsWith('tag/')) {
let tag = timeline.split('/').slice(-1)[0]
return `#${tag} timeline for ${$currentInstance}`
} else if (timeline.startsWith('account/')) {
let account = timeline.split('/').slice(-1)[0]
return `Account #${account} on ${$currentInstance}`
}
}
},
store: () => store,
components: {
VirtualList
},
methods: {
initialize() {
if (this.store.get('initialized') || !this.store.get('statusIds') || !this.store.get('statusIds').length) {
return
}
initializeTimeline()
},
onScrollToBottom() {
if (!this.store.get('initialized') || this.store.get('runningUpdate')) {
return
}
fetchStatusesOnScrollToBottom()
}
}
}
</script>