pinafore/routes/_components/Timeline.html
Nolan Lawson 697170b04a refactor
2018-01-17 08:20:41 -08:00

54 lines
1.3 KiB
HTML

<div class="timeline">
<VirtualList component="{{StatusListItem}}"
items="{{statuses}}"
on:scrollToBottom="onScrollToBottom()" />
</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'
import { mark, stop } from '../_utils/marks'
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,
onScrollToBottom() {
mark('onScrollToBottom')
let statuses = this.get('statuses')
if (statuses) {
let itemsToAdd = createData()
this.addItems(itemsToAdd)
}
stop('onScrollToBottom')
},
addItems(items) {
this.splice('statuses', this.get('statuses').length, 0, ...items)
}
}
}
</script>