2023-05-03 13:28:39 +00:00
|
|
|
import { Record } from 'immutable';
|
2023-05-10 10:59:29 +00:00
|
|
|
|
2023-05-03 13:28:39 +00:00
|
|
|
import type { Action } from 'redux';
|
2023-05-10 10:59:29 +00:00
|
|
|
|
2023-05-03 13:28:39 +00:00
|
|
|
import { focusApp, unfocusApp } from '../actions/app';
|
2023-05-10 10:59:29 +00:00
|
|
|
import { NOTIFICATIONS_UPDATE } from '../actions/notifications';
|
2023-05-03 13:28:39 +00:00
|
|
|
|
2023-05-10 10:59:29 +00:00
|
|
|
interface MissedUpdatesState {
|
2023-05-03 13:28:39 +00:00
|
|
|
focused: boolean;
|
|
|
|
unread: number;
|
2023-05-10 10:59:29 +00:00
|
|
|
}
|
2023-05-03 13:28:39 +00:00
|
|
|
const initialState = Record<MissedUpdatesState>({
|
|
|
|
focused: true,
|
|
|
|
unread: 0,
|
|
|
|
})();
|
|
|
|
|
2023-05-09 01:11:56 +00:00
|
|
|
export function missedUpdatesReducer(
|
2023-05-03 13:28:39 +00:00
|
|
|
state = initialState,
|
2023-05-09 17:02:12 +00:00
|
|
|
action: Action<string>
|
2023-05-03 13:28:39 +00:00
|
|
|
) {
|
|
|
|
switch (action.type) {
|
2023-05-09 17:02:12 +00:00
|
|
|
case focusApp.type:
|
|
|
|
return state.set('focused', true).set('unread', 0);
|
|
|
|
case unfocusApp.type:
|
|
|
|
return state.set('focused', false);
|
|
|
|
case NOTIFICATIONS_UPDATE:
|
|
|
|
return state.get('focused')
|
|
|
|
? state
|
|
|
|
: state.update('unread', (x) => x + 1);
|
|
|
|
default:
|
|
|
|
return state;
|
2023-05-03 13:28:39 +00:00
|
|
|
}
|
|
|
|
}
|