diff --git a/components/pages/Home.tsx b/components/pages/Home.tsx index 2068f8b..b7c8148 100644 --- a/components/pages/Home.tsx +++ b/components/pages/Home.tsx @@ -50,7 +50,14 @@ import { logOutSharp, documentText, } from 'ionicons/icons' -import { RefObject, useCallback, useEffect, useRef, useState } from 'react' +import { + ComponentProps, + RefObject, + useCallback, + useEffect, + useRef, + useState, +} from 'react' import { Link } from 'react-router-dom' import { CreatedTodo, db, Todo } from '../db' import NoteProviders from '../notes/providers' @@ -124,11 +131,11 @@ const Home = () => { // Creating todo stuff const fab = useRef(null) + const [createTodoModalOpen, setCreateTodoModalOpen] = useState(false) const openCreateTodoModal = useCallback(() => { setCreateTodoModalOpen(true) if (fab.current) fab.current.activated = true }, [fab]) - const [createTodoModalOpen, setCreateTodoModalOpen] = useState(false) const contentRef = useRef(null) @@ -200,6 +207,9 @@ const Home = () => { { + setCreateTodoModalOpen(false) + }} /> @@ -685,9 +695,11 @@ export const IceboxItem = ({ export const CreateTodoModal = ({ fab, open, + onWillDismiss, }: { fab: RefObject open: boolean + onWillDismiss: ComponentProps['onWillDismiss'] }) => { const modal = useRef(null) @@ -709,14 +721,6 @@ export const CreateTodoModal = ({ }, [noteProvider], ) - function onWillDismiss(event: CustomEvent) { - if (event.detail.role === 'confirm') { - createTodo({ - title: input.current?.value, - note: noteInput.current?.value, - }) - } - } useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { @@ -738,7 +742,13 @@ export const CreateTodoModal = ({ trigger="open-modal" onDidPresent={() => input.current?.setFocus()} onWillDismiss={event => { - onWillDismiss(event) + onWillDismiss?.(event) + if (event.detail.role === 'confirm') { + createTodo({ + title: input.current?.value, + note: noteInput.current?.value, + }) + } if (fab.current) fab.current.activated = false }} >