pinafore/src/routes/_actions/showMoreAndScrollToTop.js
Nolan Lawson ae3bd2bda2
perf: make timeline rendering less janky (#1747)
* perf: make timeline rendering less janky

1. Ensures all statuses are rendered from top to bottom (no more shuffling-card-effect rendering)
2. Wraps all individual status renders in their own requestIdleCallback to improve input responsiveness especially only slow devices like Nexus 5.

* fix focus restoration

* only do rIC on mobile
2020-04-26 16:54:00 -07:00

30 lines
1.1 KiB
JavaScript

import { showMoreItemsForCurrentTimeline } from './timeline'
import { scrollToTop } from '../_utils/scrollToTop'
import { createStatusOrNotificationUuid } from '../_utils/createStatusOrNotificationUuid'
import { store } from '../_store/store'
import { tryToFocusElement } from '../_utils/tryToFocusElement'
export function showMoreAndScrollToTop () {
// Similar to Twitter, pressing "." will click the "show more" button and select
// the first toot.
showMoreItemsForCurrentTimeline()
const {
currentInstance,
timelineItemSummaries,
currentTimelineType,
currentTimelineValue
} = store.get()
const firstItemSummary = timelineItemSummaries && timelineItemSummaries[0]
if (!firstItemSummary) {
return
}
const notificationId = currentTimelineType === 'notifications' && firstItemSummary.id
const statusId = currentTimelineType !== 'notifications' && firstItemSummary.id
scrollToTop(/* smooth */ false)
const id = createStatusOrNotificationUuid(
currentInstance, currentTimelineType,
currentTimelineValue, notificationId, statusId
)
tryToFocusElement(id)
}