2018-12-23 10:10:16 -08:00
|
|
|
import { get } from '../../_utils/lodash-lite'
|
2019-03-03 13:24:55 -08:00
|
|
|
import { getFirstIdFromItemSummaries, getLastIdFromItemSummaries } from '../../_utils/getIdFromItemSummaries'
|
2018-02-10 13:57:04 -08:00
|
|
|
|
2018-03-04 12:55:45 -08:00
|
|
|
function computeForTimeline (store, key, defaultValue) {
|
|
|
|
store.compute(key,
|
|
|
|
['currentInstance', 'currentTimeline', `timelineData_${key}`],
|
2018-05-06 17:35:22 -07:00
|
|
|
(currentInstance, currentTimeline, root) => (
|
|
|
|
get(root, [currentInstance, currentTimeline], defaultValue)
|
|
|
|
)
|
|
|
|
)
|
2018-02-10 13:57:04 -08:00
|
|
|
}
|
|
|
|
|
2018-02-08 22:29:29 -08:00
|
|
|
export function timelineComputations (store) {
|
2019-03-03 13:24:55 -08:00
|
|
|
computeForTimeline(store, 'timelineItemSummaries', null)
|
|
|
|
computeForTimeline(store, 'timelineItemSummariesToAdd', null)
|
2018-03-04 12:55:45 -08:00
|
|
|
computeForTimeline(store, 'runningUpdate', false)
|
2019-02-23 12:32:00 -08:00
|
|
|
computeForTimeline(store, 'lastFocusedElementId', null)
|
2018-03-04 12:55:45 -08:00
|
|
|
computeForTimeline(store, 'ignoreBlurEvents', false)
|
|
|
|
computeForTimeline(store, 'showHeader', false)
|
|
|
|
computeForTimeline(store, 'shouldShowHeader', false)
|
2019-03-03 13:24:55 -08:00
|
|
|
computeForTimeline(store, 'timelineItemSummariesAreStale', false)
|
2018-03-04 12:55:45 -08:00
|
|
|
|
2019-03-03 13:24:55 -08:00
|
|
|
store.compute('firstTimelineItemId', ['timelineItemSummaries'], (timelineItemSummaries) => (
|
|
|
|
getFirstIdFromItemSummaries(timelineItemSummaries)
|
|
|
|
))
|
|
|
|
store.compute('lastTimelineItemId', ['timelineItemSummaries'], (timelineItemSummaries) => (
|
|
|
|
getLastIdFromItemSummaries(timelineItemSummaries)
|
|
|
|
))
|
2018-01-28 13:09:39 -08:00
|
|
|
|
2018-03-04 12:55:45 -08:00
|
|
|
store.compute('numberOfNotifications',
|
2019-03-03 13:24:55 -08:00
|
|
|
[`timelineData_timelineItemSummariesToAdd`, 'currentInstance'],
|
2019-02-18 16:27:52 -08:00
|
|
|
(root, currentInstance) => (
|
|
|
|
(root && root[currentInstance] && root[currentInstance].notifications &&
|
|
|
|
root[currentInstance].notifications.length) || 0
|
|
|
|
)
|
2018-03-04 12:55:45 -08:00
|
|
|
)
|
2018-02-10 13:57:04 -08:00
|
|
|
|
2018-03-04 12:55:45 -08:00
|
|
|
store.compute('hasNotifications',
|
2019-02-18 16:27:52 -08:00
|
|
|
['numberOfNotifications', 'currentPage'],
|
|
|
|
(numberOfNotifications, currentPage) => currentPage !== 'notifications' && !!numberOfNotifications
|
2018-03-04 12:55:45 -08:00
|
|
|
)
|
2018-02-08 22:29:29 -08:00
|
|
|
}
|