From ef24dc63b4f374e0288b631db290644acd94f6c1 Mon Sep 17 00:00:00 2001 From: Daniel Metcalfe Date: Thu, 18 Jul 2024 09:01:37 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=20Misc=20lint=20warnings=20fixed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/pages/Home.tsx | 53 +++++++++++------------------------ components/todos/EditTodo.tsx | 40 ++++++++++++-------------- 2 files changed, 35 insertions(+), 58 deletions(-) diff --git a/components/pages/Home.tsx b/components/pages/Home.tsx index 588a981..6b4a1bb 100644 --- a/components/pages/Home.tsx +++ b/components/pages/Home.tsx @@ -124,7 +124,6 @@ const Home = () => { const contentRef = useRef(null) useGlobalKeyboardShortcuts(contentRef, searchbarRef, openCreateTodoModal) - useSearchKeyboardShortcuts(searchbarRef) const [enablePagination, setEnablePagination] = useState(false) @@ -237,6 +236,12 @@ const Home = () => { { + if (event.key === 'Escape') { + event.preventDefault() + searchbarRef.current?.getElementsByTagName('input')[0].blur() + } + }} debounce={100} onIonInput={ev => handleInput(ev)} > @@ -320,12 +325,13 @@ export const MiscMenu = () => { type?: string apiKey?: string }>({}) + const noteProviderSettings = settings['#noteProvider'] // Gross hack required because settings is initially undefined until the query resolves which doesn't re-trigger the state useEffect(() => { - if (settings['#noteProvider']) { - setNoteProvider(settings['#noteProvider']) + if (noteProviderSettings) { + setNoteProvider(noteProviderSettings) } - }, [settings['#noteProvider']]) + }, [noteProviderSettings]) return ( { - const handleKeyDown = (event: KeyboardEvent) => { - if (event.key === 'Enter') { - event.preventDefault() - modal.current?.dismiss({}, 'confirm') - } - } - modal.current?.addEventListener('keydown', handleKeyDown) - return () => { - modal.current?.removeEventListener('keydown', handleKeyDown) - } - }, [createTodo]) - return ( input.current?.setFocus()} + onKeyDown={event => { + if (event.key === 'Enter') { + event.preventDefault() + modal.current?.dismiss({}, 'confirm') + } + }} onWillDismiss={event => { onWillDismiss?.(event) if (event.detail.role === 'confirm') { @@ -868,22 +866,5 @@ function useGlobalKeyboardShortcuts( return () => { document.removeEventListener('keydown', handleKeyDown) } - }, [openCreateTodoModal]) -} - -function useSearchKeyboardShortcuts( - searchbarRef: RefObject, -) { - useEffect(() => { - const handleKeyDown = (event: KeyboardEvent) => { - if (event.key === 'Escape') { - event.preventDefault() - searchbarRef.current?.getElementsByTagName('input')[0].blur() - } - } - searchbarRef.current?.addEventListener('keydown', handleKeyDown) - return () => { - searchbarRef.current?.removeEventListener('keydown', handleKeyDown) - } - }) + }, [contentRef, openCreateTodoModal, searchbarRef]) } diff --git a/components/todos/EditTodo.tsx b/components/todos/EditTodo.tsx index 6a22a00..7925cfb 100644 --- a/components/todos/EditTodo.tsx +++ b/components/todos/EditTodo.tsx @@ -12,9 +12,9 @@ import { useIonModal, } from '@ionic/react' import { openOutline } from 'ionicons/icons' -import { useCallback, useEffect, useRef, useState } from 'react' -import useNoteProvider from '../notes/useNoteProvider' +import { useCallback, useEffect, useRef } from 'react' import { CreatedTodo, db } from '../db' +import useNoteProvider from '../notes/useNoteProvider' import useSelectedTodo from './SelectedTodo' export function EditTodoModal({ @@ -34,27 +34,23 @@ export function EditTodoModal({ const noteProvider = useNoteProvider() - useEffect(() => { - const handleKeyDown = (event: KeyboardEvent) => { - if (event.key === 'Enter') { - event.preventDefault() - dismiss( - { - title: input.current?.value, - note: noteInput.current?.value, - }, - 'confirm', - ) - } - } - page.current?.addEventListener('keydown', handleKeyDown) - return () => { - page.current?.removeEventListener('keydown', handleKeyDown) - } - }, [dismiss]) - return ( - + { + if (event.key === 'Enter') { + event.preventDefault() + dismiss( + { + ...todo, + title: input.current?.value, + note: noteInput.current?.value, + }, + 'confirm', + ) + } + }} + > Edit todo