2023-05-03 16:28:39 +03:00
|
|
|
import { Record } from 'immutable';
|
|
|
|
import type { Action } from 'redux';
|
|
|
|
import { NOTIFICATIONS_UPDATE } from '../actions/notifications';
|
|
|
|
import { focusApp, unfocusApp } from '../actions/app';
|
|
|
|
|
|
|
|
type MissedUpdatesState = {
|
|
|
|
focused: boolean;
|
|
|
|
unread: number;
|
|
|
|
};
|
|
|
|
const initialState = Record<MissedUpdatesState>({
|
|
|
|
focused: true,
|
|
|
|
unread: 0,
|
|
|
|
})();
|
|
|
|
|
2023-05-09 04:11:56 +03:00
|
|
|
export function missedUpdatesReducer(
|
2023-05-03 16:28:39 +03:00
|
|
|
state = initialState,
|
2023-05-09 20:02:12 +03:00
|
|
|
action: Action<string>
|
2023-05-03 16:28:39 +03:00
|
|
|
) {
|
|
|
|
switch (action.type) {
|
2023-05-09 20:02:12 +03: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 16:28:39 +03:00
|
|
|
}
|
|
|
|
}
|