Your favorite shift management application!
feat: Adds explicit Add button for new notes (#48)
panteLbec5c36a4e4f
diff --git a/components/note-dialog.tsx b/components/note-dialog.tsxindex 9bea59c..91f7704 100644--- a/components/note-dialog.tsx+++ b/components/note-dialog.tsx@@ -42,6 +42,7 @@ export function NoteDialog({const initialNoteRef = useRef<string>("");const saveTimeoutRef = useRef<NodeJS.Timeout | null>(null);const isInitialMount = useRef(true);+ const isNewNote = !note;useEffect(() => {if (open) {@@ -58,9 +59,9 @@ export function NoteDialog({}}, [open, note]);- // Handle dialog close with immediate save if needed+ // Handle dialog close with immediate save if needed (only for existing notes)const handleDialogClose = (open: boolean) => {- if (!open && noteText !== initialNoteRef.current) {+ if (!open && !isNewNote && noteText !== initialNoteRef.current) {// Cancel pending timeoutif (saveTimeoutRef.current) {clearTimeout(saveTimeoutRef.current);@@ -74,9 +75,9 @@ export function NoteDialog({onOpenChange(open);};- // Auto-save with debouncing+ // Auto-save with debouncing (only for existing notes)useEffect(() => {- if (!open) return;+ if (!open || isNewNote) return;// Skip initial mountif (isInitialMount.current) {@@ -104,7 +105,7 @@ export function NoteDialog({clearTimeout(saveTimeoutRef.current);}};- }, [noteText, open, onSubmit, onDelete, note]);+ }, [noteText, open, onSubmit, isNewNote]);const handleDelete = () => {if (onDelete) {@@ -113,6 +114,13 @@ export function NoteDialog({}};+ const handleAdd = () => {+ if (noteText.trim()) {+ onSubmit(noteText);+ onOpenChange(false);+ }+ };+const formattedDate = selectedDate? format(selectedDate, "PPP", { locale: dateLocale }): "";@@ -173,6 +181,16 @@ export function NoteDialog({>{t("common.close")}</Button>+ {isNewNote && (+ <Button+ type="button"+ onClick={handleAdd}+ disabled={!noteText.trim()}+ className="h-11 shadow-lg hover:shadow-xl transition-all"+ >+ {t("common.add")}+ </Button>+ )}</div></div></div>