pinafore/routes/_components/timeline/Timeline.html
2018-01-30 22:46:35 -08:00

124 lines
4.1 KiB
HTML

<div class="timeline" role="feed" aria-label="{{label}}">
{{#if !$initialized}}
<div class="loading-page">
<LoadingSpinner />
</div>
{{/if}}
{{#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}}"
realm="{{$currentInstance + '/' + timeline}}"
/>
{{/if}}
</div>
<style>
.timeline {
min-height: 60vh;
position: relative;
}
.loading-page {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 150px;
display: flex;
align-items: center;
justify-content: center;
z-index: 50;
}
</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'
import LoadingSpinner from '../LoadingSpinner.html'
export default {
async oncreate() {
console.log('timeline oncreate()')
setupTimeline()
},
data: () => ({
StatusVirtualListItem,
LoadingFooter,
Status
}),
computed: {
makeProps: ($currentInstance, timelineType, timelineValue) => async (statusId) => ({
timelineType: timelineType,
timelineValue: timelineValue,
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,
LoadingSpinner
},
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>