diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index 7e081345..d21d24fa 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -42,27 +42,26 @@ export default function Navigation({ const [selectedDocsModalState, setSelectedDocsModalState] = useState(isSelectedDocsSet ? 'INACTIVE' : 'ACTIVE'); - const navDiv = useRef(null); + const navRef = useRef(null); useOutsideAlerter( - navDiv, + navRef, () => { if ( window.matchMedia('(max-width: 768px)').matches && navState === 'ACTIVE' && - apiKeyModalState === 'INACTIVE' && - selectedDocsModalState === 'INACTIVE' && - !isDocsListOpen + apiKeyModalState === 'INACTIVE' ) { setNavState('INACTIVE'); + setIsDocsListOpen(false); } }, - [navState, isDocsListOpen, apiKeyModalState, selectedDocsModalState], + [isDocsListOpen, apiKeyModalState], ); return ( <>
( ref: RefObject, handler: () => void, - deps: any[], + additionalDeps: unknown[], ) { useEffect(() => { function handleClickOutside(this: Document, event: MouseEvent) { @@ -15,5 +15,5 @@ export function useOutsideAlerter( return () => { document.removeEventListener('mousedown', handleClickOutside); }; - }, [ref, ...deps]); + }, [ref, ...additionalDeps]); } diff --git a/frontend/src/preferences/APIKeyModal.tsx b/frontend/src/preferences/APIKeyModal.tsx index 5300bf7a..d068aa42 100644 --- a/frontend/src/preferences/APIKeyModal.tsx +++ b/frontend/src/preferences/APIKeyModal.tsx @@ -1,7 +1,8 @@ -import { useState } from 'react'; +import { useRef, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { ActiveState } from '../models/misc'; import { selectApiKey, setApiKey } from './preferenceSlice'; +import { useOutsideAlerter } from './../hooks'; export default function APIKeyModal({ modalState, @@ -16,6 +17,20 @@ export default function APIKeyModal({ const apiKey = useSelector(selectApiKey); const [key, setKey] = useState(apiKey); const [isError, setIsError] = useState(false); + const modalRef = useRef(null); + + useOutsideAlerter( + modalRef, + () => { + if ( + window.matchMedia('(max-width: 768px)').matches && + modalState === 'ACTIVE' + ) { + setModalState('INACTIVE'); + } + }, + [modalState], + ); function handleSubmit() { if (key.length <= 1) { @@ -39,7 +54,10 @@ export default function APIKeyModal({ modalState === 'ACTIVE' ? 'visible' : 'hidden' } absolute z-30 h-screen w-screen bg-gray-alpha`} > -
+

OpenAI API Key

Before you can start using DocsGPT we need you to provide an API key