diff --git a/src/utils/asyncStorageUtils.ts b/src/utils/asyncStorageUtils.ts index a0e09e3..c934f08 100644 --- a/src/utils/asyncStorageUtils.ts +++ b/src/utils/asyncStorageUtils.ts @@ -63,17 +63,19 @@ export interface INotificationStore { export const setNotificationStore = async ( notificationStore: INotificationStore, ) => { - try { - if (!notificationStore.lastChecked) { - notificationStore.lastChecked = await ( - await getAsyncStorageItem(AsyncStorageKeys.NOTIFICATION) - ).lastChecked; - } - await setAsyncStorageItem( - AsyncStorageKeys.NOTIFICATION, - notificationStore, - ); - } catch (error) {} + const currentNotificationStore: INotificationStore = await getAsyncStorageItem( + AsyncStorageKeys.NOTIFICATION, + ); + + const notificationStoreToSet: INotificationStore = { + notified: notificationStore.notified, + lastChecked: currentNotificationStore?.lastChecked, + }; + + await setAsyncStorageItem( + AsyncStorageKeys.NOTIFICATION, + notificationStoreToSet, + ); }; export interface ISettingsStore { diff --git a/src/utils/backgroundUpdater.ts b/src/utils/backgroundUpdater.ts index cd65e51..1c8c0ef 100644 --- a/src/utils/backgroundUpdater.ts +++ b/src/utils/backgroundUpdater.ts @@ -24,10 +24,7 @@ const backgroundUpdaterTask = async ({ taskId, timeout }: HeadlessEvent) => { AsyncStorageKeys.SETTINGS, ); - if ( - notificationStore?.notified === true || - !settingsStore?.notificationsEnabled - ) { + if (notificationStore?.notified || !settingsStore?.notificationsEnabled) { BackgroundFetch.finish(taskId); return; } @@ -51,7 +48,9 @@ const backgroundUpdaterTask = async ({ taskId, timeout }: HeadlessEvent) => { }, 0, ); - const message = `Found ${numberOfSlots} slots for ${settings.district?.value}`; + const message = `Found ${numberOfSlots} slot${ + numberOfSlots > 1 ? 's' : '' + } for ${settings.district?.value}`; sendSlotFoundNotification(message, lastChecked); setNotificationStore({ notified: true, lastChecked }); }