pinafore/routes/_components/Timeline.html
2018-01-17 00:06:24 -08:00

68 lines
1.5 KiB
HTML

<div class="timeline">
<VirtualList component="{{StatusListItem}}"
items="{{statuses}}"
on:scrollToBottom="addMoreItems()" />
</div>
<style>
.timeline {
min-height: 50vh;
}
</style>
<script>
import { store } from '../_utils/store'
import { getHomeTimeline } from '../_utils/mastodon/oauth'
import fixture from '../_utils/fixture.json'
import StatusListItem from './StatusListItem.html'
import VirtualList from './VirtualList.html'
import { splice, push } from 'svelte-extras'
let i = -1
const createData = () => fixture.slice(0, 20).map(_ => ({
key: `${++i}`,
props: _
}))
export default {
data: () => ({
target: 'home',
statuses: createData(),
StatusListItem: StatusListItem
}),
store: () => store,
components: {
VirtualList
},
methods: {
splice: splice,
push: push,
addMoreItems() {
console.log('addMoreItems')
let statuses = this.get('statuses')
if (statuses) {
let itemsToAdd = createData()
if (itemsToAdd.length) {
}
let importantFirstItem = itemsToAdd
this.splice('statuses', statuses.length, 0, ...itemsToAdd)
}
},
addTheseItems(items) {
if (!items.length) {
return
}
this.push(items.pop())
while (items.length) {
this.addItemLazily(items.pop())
}
},
addItemLazily(item) {
requestIdleCallback(() => {
this.push(item)
})
}
}
}
</script>