diff --git a/src/App.jsx b/src/App.jsx index 1911200..86ce453 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -14,6 +14,11 @@ function App() { function queryOnChange () { let query = inputSearch.current.value query = query.replace(/[^a-zA-Z0-9\- ]/, "") + + if (query == '') { + history.pushState('', '', '#') + } + setCurrentQuery(query) dispatch(setQuery(query)) } @@ -27,15 +32,33 @@ function App() { dispatch(setShowName(checkShowName.current.checked)) } + function confirmKeyword (e) { + if (e.key === 'Enter') { + history.pushState('', '', '#' + inputSearch.current.value) + inputSearch.current.blur() + } + } + + const handleHashChange = (e) => { + // console.log(e) + inputSearch.current.value = window.location.hash.replace("#", "") + queryOnChange() + }; + useEffect(() => { inputSearch.current.focus() queryOnChange() + + window.addEventListener('hashchange', handleHashChange) + return () => { + window.removeEventListener('hashchange', handleHashChange) + } }) return ( <>
- + { currentQuery == '' ? '' : }