2020-02-12 21:30:58 +00:00
|
|
|
import { Dialogs } from '../../types/Dialogs';
|
|
|
|
import * as updateIpc from '../../shims/updateIpc';
|
2020-02-21 00:09:50 +00:00
|
|
|
import { trigger } from '../../shims/events';
|
2020-02-12 21:30:58 +00:00
|
|
|
|
|
|
|
// State
|
|
|
|
|
|
|
|
export type UpdatesStateType = {
|
|
|
|
dialogType: Dialogs;
|
2020-02-21 00:09:50 +00:00
|
|
|
didSnooze: boolean;
|
|
|
|
showEventsCount: number;
|
2020-02-12 21:30:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
|
|
|
const ACK_RENDER = 'updates/ACK_RENDER';
|
|
|
|
const DISMISS_DIALOG = 'updates/DISMISS_DIALOG';
|
|
|
|
const SHOW_UPDATE_DIALOG = 'updates/SHOW_UPDATE_DIALOG';
|
2020-02-21 00:09:50 +00:00
|
|
|
const SNOOZE_UPDATE = 'updates/SNOOZE_UPDATE';
|
2020-02-12 21:30:58 +00:00
|
|
|
const START_UPDATE = 'updates/START_UPDATE';
|
|
|
|
|
|
|
|
type AckRenderAction = {
|
|
|
|
type: 'updates/ACK_RENDER';
|
|
|
|
};
|
|
|
|
|
|
|
|
type DismissDialogAction = {
|
|
|
|
type: 'updates/DISMISS_DIALOG';
|
|
|
|
};
|
|
|
|
|
|
|
|
export type ShowUpdateDialogAction = {
|
|
|
|
type: 'updates/SHOW_UPDATE_DIALOG';
|
|
|
|
payload: Dialogs;
|
|
|
|
};
|
|
|
|
|
2020-02-21 00:09:50 +00:00
|
|
|
type SnoozeUpdateActionType = {
|
|
|
|
type: 'updates/SNOOZE_UPDATE';
|
|
|
|
};
|
|
|
|
|
2020-02-12 21:30:58 +00:00
|
|
|
type StartUpdateAction = {
|
|
|
|
type: 'updates/START_UPDATE';
|
|
|
|
};
|
|
|
|
|
|
|
|
export type UpdatesActionType =
|
|
|
|
| AckRenderAction
|
|
|
|
| DismissDialogAction
|
|
|
|
| ShowUpdateDialogAction
|
2020-02-21 00:09:50 +00:00
|
|
|
| SnoozeUpdateActionType
|
2020-02-12 21:30:58 +00:00
|
|
|
| StartUpdateAction;
|
|
|
|
|
|
|
|
// Action Creators
|
|
|
|
|
|
|
|
function ackRender(): AckRenderAction {
|
|
|
|
updateIpc.ackRender();
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: ACK_RENDER,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function dismissDialog(): DismissDialogAction {
|
|
|
|
return {
|
|
|
|
type: DISMISS_DIALOG,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function showUpdateDialog(dialogType: Dialogs): ShowUpdateDialogAction {
|
|
|
|
return {
|
|
|
|
type: SHOW_UPDATE_DIALOG,
|
|
|
|
payload: dialogType,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-21 00:09:50 +00:00
|
|
|
const SNOOZE_TIMER = 60 * 1000 * 30;
|
|
|
|
|
|
|
|
function snoozeUpdate(): SnoozeUpdateActionType {
|
|
|
|
setTimeout(() => {
|
|
|
|
trigger('snooze-update');
|
|
|
|
}, SNOOZE_TIMER);
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: SNOOZE_UPDATE,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-12 21:30:58 +00:00
|
|
|
function startUpdate(): StartUpdateAction {
|
|
|
|
updateIpc.startUpdate();
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: START_UPDATE,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
ackRender,
|
|
|
|
dismissDialog,
|
|
|
|
showUpdateDialog,
|
2020-02-21 00:09:50 +00:00
|
|
|
snoozeUpdate,
|
2020-02-12 21:30:58 +00:00
|
|
|
startUpdate,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Reducer
|
|
|
|
|
|
|
|
function getEmptyState(): UpdatesStateType {
|
|
|
|
return {
|
|
|
|
dialogType: Dialogs.None,
|
2020-02-21 00:09:50 +00:00
|
|
|
didSnooze: false,
|
|
|
|
showEventsCount: 0,
|
2020-02-12 21:30:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function reducer(
|
|
|
|
state: UpdatesStateType = getEmptyState(),
|
|
|
|
action: UpdatesActionType
|
|
|
|
): UpdatesStateType {
|
|
|
|
if (action.type === SHOW_UPDATE_DIALOG) {
|
|
|
|
return {
|
|
|
|
dialogType: action.payload,
|
2020-02-21 00:09:50 +00:00
|
|
|
didSnooze: state.didSnooze,
|
|
|
|
showEventsCount: state.showEventsCount + 1,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === SNOOZE_UPDATE) {
|
|
|
|
return {
|
|
|
|
dialogType: Dialogs.None,
|
|
|
|
didSnooze: true,
|
|
|
|
showEventsCount: state.showEventsCount,
|
2020-02-12 21:30:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-03-30 16:13:51 +00:00
|
|
|
if (action.type === START_UPDATE) {
|
|
|
|
return {
|
|
|
|
dialogType: Dialogs.None,
|
|
|
|
didSnooze: state.didSnooze,
|
|
|
|
showEventsCount: state.showEventsCount,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-12 21:30:58 +00:00
|
|
|
if (
|
|
|
|
action.type === DISMISS_DIALOG &&
|
|
|
|
state.dialogType === Dialogs.MacOS_Read_Only
|
|
|
|
) {
|
|
|
|
return {
|
|
|
|
dialogType: Dialogs.None,
|
2020-02-21 00:09:50 +00:00
|
|
|
didSnooze: state.didSnooze,
|
|
|
|
showEventsCount: state.showEventsCount,
|
2020-02-12 21:30:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|