From bb7cc2af044db9cae09028e37587b3b6e5e164e8 Mon Sep 17 00:00:00 2001 From: tiddlygit-test Date: Sun, 31 Jan 2021 17:01:01 +0800 Subject: [PATCH] refactor: notification listeners --- src/components/dialog-notifications/index.tsx | 10 +++++----- src/senders/index.ts | 4 ---- src/state/notifications/reducers.ts | 4 +--- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/components/dialog-notifications/index.tsx b/src/components/dialog-notifications/index.tsx index c83c71c7..e46f6958 100644 --- a/src/components/dialog-notifications/index.tsx +++ b/src/components/dialog-notifications/index.tsx @@ -132,8 +132,8 @@ const DialogPauseNotifications = (props: DialogPauseNotificationsProps) => { }, ]; - const pauseNotif = (tilDate: any) => { - requestSetPreference('pauseNotifications', `pause:${tilDate.toString()}`); + const pauseNotification = (tilDate: Date): void => { + void window.service.preference.set('pauseNotifications', `pause:${tilDate.toString()}`); void window.service.notification.show({ title: 'Notifications paused', body: `Notifications paused until ${formatDate(tilDate)}.`, @@ -182,7 +182,7 @@ const DialogPauseNotifications = (props: DialogPauseNotificationsProps) => { }> {quickShortcuts.map((shortcut) => ( - pauseNotif(shortcut.calcDate())}> + pauseNotification(shortcut.calcDate())}> {shortcut.name} ))} @@ -209,7 +209,7 @@ const DialogPauseNotifications = (props: DialogPauseNotificationsProps) => { return ( Pause notifications}> {quickShortcuts.map((shortcut) => ( - pauseNotif(shortcut.calcDate())}> + pauseNotification(shortcut.calcDate())}> ))} @@ -236,7 +236,7 @@ const DialogPauseNotifications = (props: DialogPauseNotificationsProps) => { } - onChange={pauseNotif} + onChange={pauseNotification} label="Custom" open={showDateTimePicker} onOpen={() => onUpdateShowDateTimePicker(true)} diff --git a/src/senders/index.ts b/src/senders/index.ts index 39e0b2a7..38716071 100644 --- a/src/senders/index.ts +++ b/src/senders/index.ts @@ -12,10 +12,6 @@ export const getShouldUseDarkColors = async (): Promise => { await ipcRenderer.invoke('get-should-use-dark-colors'); }; -// Notifications -export const requestUpdatePauseNotificationsInfo = async () => await ipcRenderer.invoke('request-update-pause-notifications-info'); -export const getPauseNotificationsInfo = () => ipcRenderer.invokeSync('get-pause-notifications-info'); - // Preferences export const requestSetPreference = async (name: string, value: JsonValue) => await ipcRenderer.invoke('request-set-preference', name, value); export const requestResetPreferences = async () => await ipcRenderer.invoke('request-reset-preferences'); diff --git a/src/state/notifications/reducers.ts b/src/state/notifications/reducers.ts index 6dcca452..c666f7be 100755 --- a/src/state/notifications/reducers.ts +++ b/src/state/notifications/reducers.ts @@ -2,8 +2,6 @@ import { combineReducers } from 'redux'; import { UPDATE_PAUSE_NOTIFICATIONS_INFO, UPDATE_SHOW_DATE_TIME_PICKER } from '../../constants/actions'; -import { getPauseNotificationsInfo } from '../../senders'; - const showDateTimePicker = (state = false, action: any) => { switch (action.type) { case UPDATE_SHOW_DATE_TIME_PICKER: { @@ -15,7 +13,7 @@ const showDateTimePicker = (state = false, action: any) => { } }; -const pauseNotificationsInfo = (state = getPauseNotificationsInfo(), action: any) => { +const pauseNotificationsInfo = (state = await window.service.notification.getPauseNotificationsInfo(), action: any) => { switch (action.type) { case UPDATE_PAUSE_NOTIFICATIONS_INFO: { return action.pauseNotificationsInfo;