forked from cybrespace/pinafore
103 lines
3.6 KiB
HTML
103 lines
3.6 KiB
HTML
<div class="timeline" role="feed" aria-label="{{label}}">
|
|
{{#if virtual}}
|
|
<VirtualList component="{{StatusVirtualListItem}}"
|
|
:makeProps
|
|
items="{{$statusIds}}"
|
|
on:scrollToBottom="onScrollToBottom()"
|
|
shown="{{$initialized}}"
|
|
footerComponent="{{LoadingFooter}}"
|
|
showFooter="{{$initialized && $runningUpdate}}"
|
|
realm="{{$currentInstance + '/' + timeline}}"
|
|
on:initializedVisibleItems="initialize()"
|
|
/>
|
|
{{else}}
|
|
<!-- if this is a status thread, it's easier to just render the
|
|
whole thing rather than use a virtual list -->
|
|
<PseudoVirtualList component="{{StatusVirtualListItem}}"
|
|
:makeProps
|
|
items="{{$statusIds}}"
|
|
shown="{{$initialized}}"
|
|
on:initializedVisibleItems="initialize()"
|
|
scrollToItem="{{timelineValue}}"
|
|
/>
|
|
{{/if}}
|
|
</div>
|
|
<style>
|
|
.timeline {
|
|
min-height: 60vh;
|
|
}
|
|
</style>
|
|
<script>
|
|
import { store } from '../../_store/store'
|
|
import StatusVirtualListItem from './StatusVirtualListItem.html'
|
|
import Status from '../status/Status.html'
|
|
import PseudoVirtualList from '../pseudoVirtualList/PseudoVirtualList.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() {
|
|
console.log('timeline oncreate()')
|
|
setupTimeline()
|
|
},
|
|
data: () => ({
|
|
StatusVirtualListItem,
|
|
LoadingFooter,
|
|
Status
|
|
}),
|
|
computed: {
|
|
makeProps: ($currentInstance, timelineType) => async (statusId) => ({
|
|
timelineType: timelineType,
|
|
status: await database.getStatus($currentInstance, statusId)
|
|
}),
|
|
label: (timeline, $currentInstance, timelineType, timelineValue) => {
|
|
if (timelines[timeline]) {
|
|
return `${timelines[timeline].label} timeline for ${$currentInstance}`
|
|
}
|
|
|
|
switch (timelineType) {
|
|
case 'tag':
|
|
return `#${timelineValue} timeline for ${$currentInstance}`
|
|
case 'status':
|
|
return 'Status context'
|
|
case 'account':
|
|
return `Account #${timelineValue} on ${$currentInstance}`
|
|
}
|
|
},
|
|
timelineType: (timeline) => {
|
|
return timeline.split('/')[0]
|
|
},
|
|
timelineValue: (timeline) => {
|
|
return timeline.split('/').slice(-1)[0]
|
|
},
|
|
// for threads, it's simpler to just render all items due to need to scroll to the right item
|
|
// TODO: this can be optimized to use a virtual list
|
|
virtual: (timelineType) => timelineType !=='status'
|
|
},
|
|
store: () => store,
|
|
components: {
|
|
VirtualList,
|
|
PseudoVirtualList
|
|
},
|
|
methods: {
|
|
initialize() {
|
|
if (this.store.get('initialized') || !this.store.get('statusIds') || !this.store.get('statusIds').length) {
|
|
return
|
|
}
|
|
console.log('timeline initialize()')
|
|
initializeTimeline()
|
|
},
|
|
onScrollToBottom() {
|
|
if (!this.store.get('initialized') ||
|
|
this.store.get('runningUpdate') ||
|
|
this.get('timelineType') === 'status') { // for status contexts, we've already fetched the whole thread
|
|
return
|
|
}
|
|
fetchStatusesOnScrollToBottom()
|
|
}
|
|
}
|
|
}
|
|
</script> |