From 96d1d50bae35157f9d61d36384a45e3fef725482 Mon Sep 17 00:00:00 2001 From: Sebastian Barry Date: Fri, 3 Nov 2023 16:01:50 -0600 Subject: [PATCH] Update notifscheduler to export functions instead of using hooks --- www/js/splash/notifScheduler.ts | 38 ++++++--------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/www/js/splash/notifScheduler.ts b/www/js/splash/notifScheduler.ts index 723b949ca..e41430529 100644 --- a/www/js/splash/notifScheduler.ts +++ b/www/js/splash/notifScheduler.ts @@ -1,6 +1,5 @@ import angular from 'angular'; import React, { useEffect, useState } from 'react'; -import { getConfig } from '../config/dynamicConfig'; import useAppConfig from '../useAppConfig'; import { addStatReading, statKeys } from '../plugin/clientStats'; import { getUser, updateUser } from '../commHelper'; @@ -79,7 +78,7 @@ function debugGetScheduled(prefix) { } //new method to fetch notifications -const getScheduledNotifs = function () { +export const getScheduledNotifs = function () { return new Promise((resolve, reject) => { /* if the notifications are still in active scheduling it causes problems anywhere from 0-n of the scheduled notifs are displayed @@ -161,10 +160,9 @@ const scheduleNotifs = (scheme, notifTimes) => { }; // determines when notifications are needed, and schedules them if not already scheduled -const update = async (reminderSchemes) => { - const { reminder_assignment, reminder_join_date, reminder_time_of_day } = await getReminderPrefs( - reminderSchemes, - ); +export const updateScheduledNotifs = async (reminderSchemes): Promise => { + const { reminder_assignment, reminder_join_date, reminder_time_of_day } = + await getReminderPrefs(reminderSchemes); var scheme = {}; try { scheme = reminderSchemes[reminder_assignment]; @@ -228,7 +226,7 @@ const initReminderPrefs = (reminderSchemes) => { // reminder_time_of_day: string; // } -const getReminderPrefs = async (reminderSchemes): Promise => { +export const getReminderPrefs = async (reminderSchemes): Promise => { const user = (await getUser()) as any; if (user?.reminder_assignment && user?.reminder_join_date && user?.reminder_time_of_day) { console.log('User already has reminder prefs, returning them', user); @@ -241,11 +239,11 @@ const getReminderPrefs = async (reminderSchemes): Promise => { await setReminderPrefs(initPrefs, reminderSchemes); return { ...user, ...initPrefs }; // user profile + the new prefs }; -const setReminderPrefs = async (newPrefs, reminderSchemes) => { +export const setReminderPrefs = async (newPrefs, reminderSchemes) => { await updateUser(newPrefs); const updatePromise = new Promise((resolve, reject) => { //enforcing update before moving on - update(reminderSchemes).then(() => { + updateScheduledNotifs(reminderSchemes).then(() => { resolve(); }); }); @@ -262,25 +260,3 @@ const setReminderPrefs = async (newPrefs, reminderSchemes) => { }); return updatePromise; }; - -export function useSchedulerHelper() { - const appConfig = useAppConfig(); - const [reminderSchemes, setReminderSchemes] = useState(); - - useEffect(() => { - if (!appConfig) { - logDebug('No reminder schemes found in config, not scheduling notifications'); - return; - } - setReminderSchemes(appConfig.reminderSchemes); - }, [appConfig]); - - //setUpActions(); - update(reminderSchemes); - - return { - setReminderPrefs: (newPrefs) => setReminderPrefs(newPrefs, reminderSchemes), - getReminderPrefs: () => getReminderPrefs(reminderSchemes), - getScheduledNotifs: () => getScheduledNotifs(), - }; -}