From e9f1b2a9b49ae980b34a165d6d305c579f22c978 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Mon, 23 Jun 2025 00:54:05 -0400 Subject: [PATCH] fix: refactor getDefaultNotification to retrieve from localStorage and update notificationMetadata initialization --- src/views/components/AddTaskModal.jsx | 32 ++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/views/components/AddTaskModal.jsx b/src/views/components/AddTaskModal.jsx index 0c6d20c..1408401 100644 --- a/src/views/components/AddTaskModal.jsx +++ b/src/views/components/AddTaskModal.jsx @@ -31,6 +31,23 @@ import NotificationTemplate from '../../components/NotificationTemplate' import LearnMoreButton from './LearnMore' import RichTextEditor from './RichTextEditor' import SubTasks from './SubTask' +const getDefaultNotification = () => { + const storedDefault = localStorage.getItem('defaultNotificationTemplate') + if (storedDefault) { + return JSON.parse(storedDefault) + } + const defaultNotification = [ + { value: 1, unit: 'days', type: 'before' }, + { value: 0, unit: 'minutes', type: 'ondue' }, + { value: 1, unit: 'days', type: 'after' }, + ] + + localStorage.setItem( + 'defaultNotification', + JSON.stringify(defaultNotification), + ) + return defaultNotification +} const TaskInput = ({ autoFocus, onChoreUpdate, isModalOpen, onClose }) => { const { data: userLabels, isLoading: userLabelsLoading } = useLabels() @@ -53,7 +70,7 @@ const TaskInput = ({ autoFocus, onChoreUpdate, isModalOpen, onClose }) => { const [labelsV2, setLabelsV2] = useState([]) const [frequency, setFrequency] = useState(null) const [notificationMetadata, setNotificationMetadata] = useState({ - templates: [], + templates: getDefaultNotification(), }) const [frequencyHumanReadable, setFrequencyHumanReadable] = useState(null) const [subTasks, setSubTasks] = useState(null) @@ -635,11 +652,16 @@ const TaskInput = ({ autoFocus, onChoreUpdate, isModalOpen, onClose }) => { { - const newNotificaitonMetadata = { - ...notificationMetadata, - templates: metadata.notifications, + if ( + metadata.notifications !== + notificationMetadata.templates + ) { + const newNotificaitonMetadata = { + ...notificationMetadata, + templates: metadata.notifications, + } + setNotificationMetadata(newNotificaitonMetadata) } - setNotificationMetadata(newNotificaitonMetadata) }} value={notificationMetadata} showTimeline={false}