Skip to content

Commit

Permalink
🐛 Create todo modal not opening after first time
Browse files Browse the repository at this point in the history
  • Loading branch information
homostellaris committed Jul 16, 2024
1 parent 278b397 commit e1361de
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions components/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -124,11 +131,11 @@ const Home = () => {

// Creating todo stuff
const fab = useRef<HTMLIonFabElement>(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<HTMLIonContentElement>(null)

Expand Down Expand Up @@ -200,6 +207,9 @@ const Home = () => {
<CreateTodoModal
fab={fab}
open={createTodoModalOpen}
onWillDismiss={() => {
setCreateTodoModalOpen(false)
}}
/>
</IonContent>
<IonFooter>
Expand Down Expand Up @@ -685,9 +695,11 @@ export const IceboxItem = ({
export const CreateTodoModal = ({
fab,
open,
onWillDismiss,
}: {
fab: RefObject<HTMLIonFabElement>
open: boolean
onWillDismiss: ComponentProps<typeof IonModal>['onWillDismiss']
}) => {
const modal = useRef<HTMLIonModalElement>(null)

Expand All @@ -709,14 +721,6 @@ export const CreateTodoModal = ({
},
[noteProvider],
)
function onWillDismiss(event: CustomEvent<OverlayEventDetail>) {
if (event.detail.role === 'confirm') {
createTodo({
title: input.current?.value,
note: noteInput.current?.value,
})
}
}

useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
Expand All @@ -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
}}
>
Expand Down

0 comments on commit e1361de

Please sign in to comment.