128 lines
		
	
	
		
			No EOL
		
	
	
		
			4.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			128 lines
		
	
	
		
			No EOL
		
	
	
		
			4.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <div class="timeline" role="feed" aria-label="{{label}}">
 | |
|   {{#if !$initialized}}
 | |
|     <LoadingPage />
 | |
|   {{/if}}
 | |
|   {{#if timelineType === 'notifications'}}
 | |
|     <VirtualList component="{{NotificationVirtualListItem}}"
 | |
|                  :makeProps
 | |
|                  items="{{$timelineItemIds}}"
 | |
|                  on:scrollToBottom="onScrollToBottom()"
 | |
|                  shown="{{$initialized}}"
 | |
|                  footerComponent="{{LoadingFooter}}"
 | |
|                  showFooter="{{$initialized && $runningUpdate}}"
 | |
|                  realm="{{$currentInstance + '/' + timeline}}"
 | |
|                  on:initializedVisibleItems="initialize()"
 | |
|   />
 | |
|   {{elseif virtual}}
 | |
|     <VirtualList component="{{StatusVirtualListItem}}"
 | |
|                  :makeProps
 | |
|                  items="{{$timelineItemIds}}"
 | |
|                  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="{{$timelineItemIds}}"
 | |
|                        shown="{{$initialized}}"
 | |
|                        on:initializedVisibleItems="initialize()"
 | |
|                        scrollToItem="{{timelineValue}}"
 | |
|                        realm="{{$currentInstance + '/' + timeline}}"
 | |
|     />
 | |
|   {{/if}}
 | |
| </div>
 | |
| <style>
 | |
|   .timeline {
 | |
|     min-height: 60vh;
 | |
|     position: relative;
 | |
|   }
 | |
| </style>
 | |
| <script>
 | |
|   import { store } from '../../_store/store'
 | |
|   import StatusVirtualListItem from './StatusVirtualListItem.html'
 | |
|   import NotificationVirtualListItem from './NotificationVirtualListItem.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, fetchTimelineItemsOnScrollToBottom, setupTimeline } from '../../_actions/timeline'
 | |
|   import LoadingPage from '../LoadingPage.html'
 | |
| 
 | |
|   export default {
 | |
|     async oncreate() {
 | |
|       console.log('timeline oncreate()')
 | |
|       setupTimeline()
 | |
|     },
 | |
|     data: () => ({
 | |
|       StatusVirtualListItem,
 | |
|       NotificationVirtualListItem,
 | |
|       LoadingFooter,
 | |
|       Status
 | |
|     }),
 | |
|     computed: {
 | |
|       makeProps: ($currentInstance, timelineType, timelineValue) => async (itemId) => {
 | |
|         let res = { timelineType, timelineValue }
 | |
|         if (timelineType === 'notifications') {
 | |
|           res.notification = await database.getNotification($currentInstance, itemId)
 | |
|         } else {
 | |
|           res.status = await database.getStatus($currentInstance, itemId)
 | |
|         }
 | |
|         return res
 | |
|       },
 | |
|       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,
 | |
|       LoadingPage
 | |
|     },
 | |
|     methods: {
 | |
|       initialize() {
 | |
|         if (this.store.get('initialized') || !this.store.get('timelineItemIds') || !this.store.get('timelineItemIds').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
 | |
|         }
 | |
|         fetchTimelineItemsOnScrollToBottom()
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| </script> |