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