diff --git a/src/features/messages/MessageSearch.tsx b/src/features/messages/MessageSearch.tsx index b898b18..40f696c 100644 --- a/src/features/messages/MessageSearch.tsx +++ b/src/features/messages/MessageSearch.tsx @@ -1,4 +1,5 @@ -import { useState } from 'react'; +import { useRouter } from 'next/router'; +import { useEffect, useState } from 'react'; import { Fade } from '../../components/animations/Fade'; import { Card } from '../../components/layout/Card'; @@ -38,6 +39,9 @@ export function MessageSearch() { const [startTimeFilter, setStartTimeFilter] = useState(null); const [endTimeFilter, setEndTimeFilter] = useState(null); + // Router + const router = useRouter(); + // GraphQL query and results const { isValidInput, isError, isFetching, hasRun, messageList, isMessagesFound } = useMessageSearchQuery( @@ -72,6 +76,11 @@ export function MessageSearch() { // Keep url in sync useSyncQueryParam(QUERY_SEARCH_PARAM, isValidInput ? sanitizedInput : ''); + // Reset query input when Router to homepage (no params) + useEffect(() => { + if (router.asPath === '/') setSearchInput(''); + }, [router.asPath]); + return ( <>