Skip to content

Commit

Permalink
Restructure promise format and replaced moment with Luxon
Browse files Browse the repository at this point in the history
ProfileSettings.tsx
- 2 locations that used moment I replaced with Luxon because the notifScheduler is returning DateTime objects which don't mesh with moment
- Restructured the if(uiConfig?.reminderSchemes) in refreshNotificationSettings to execute the promises at first, and then set the data
- Some Prettier formatting took over here automatically too
  • Loading branch information
sebastianbarry committed Nov 7, 2023
1 parent 97571ee commit a29705d
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions www/js/control/ProfileSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
getReminderPrefs,
setReminderPrefs,
} from '../splash/notifScheduler';
import { DateTime } from 'luxon';

//any pure functions can go outside
const ProfileSettings = () => {
Expand Down Expand Up @@ -201,13 +202,20 @@ const ProfileSettings = () => {
const newNotificationSettings = {};

if (uiConfig?.reminderSchemes) {
const prefs = await getReminderPrefs(uiConfig.reminderSchemes);
const m = moment(prefs.reminder_time_of_day, 'HH:mm');
newNotificationSettings.prefReminderTimeVal = m.toDate();
const n = moment(newNotificationSettings.prefReminderTimeVal);
newNotificationSettings.prefReminderTime = n.format('LT');
let promiseList = [];
promiseList.push(getReminderPrefs(uiConfig.reminderSchemes));
promiseList.push(getScheduledNotifs());
let resultList = await Promise.all(promiseList);
const prefs = resultList[0];
const scheduledNotifs = resultList[1];
console.log('prefs and scheduled notifs', resultList[0], resultList[1]);

const m = DateTime.fromFormat(prefs.reminder_time_of_day, 'HH:mm');
newNotificationSettings.prefReminderTimeVal = m.toJSDate();
newNotificationSettings.prefReminderTime = m.toFormat('t');
newNotificationSettings.prefReminderTimeOnLoad = prefs.reminder_time_of_day;
newNotificationSettings.scheduledNotifs = await getScheduledNotifs();
newNotificationSettings.scheduledNotifs = scheduledNotifs;

updatePrefReminderTime(false);
}

Expand Down Expand Up @@ -276,13 +284,14 @@ const ProfileSettings = () => {
async function updatePrefReminderTime(storeNewVal = true, newTime) {
console.log(newTime);
if (storeNewVal) {
const m = moment(newTime);
const m = DateTime.fromISO(newTime);
// store in HH:mm
setReminderPrefs({ reminder_time_of_day: m.format('HH:mm') }, uiConfig.reminderSchemes).then(
() => {
refreshNotificationSettings();
},
);
setReminderPrefs(
{ reminder_time_of_day: m.toFormat('HH:mm') },
uiConfig.reminderSchemes,
).then(() => {
refreshNotificationSettings();
});
}
}

Expand Down

0 comments on commit a29705d

Please sign in to comment.