diff --git a/src/pages/Home/Home.tsx b/src/pages/Home/Home.tsx index 4f51f924..c954e52a 100644 --- a/src/pages/Home/Home.tsx +++ b/src/pages/Home/Home.tsx @@ -1,4 +1,4 @@ -import { useCallback, useMemo, useState } from 'react'; +import { useCallback, useEffect, useMemo, useState } from 'react'; import { useSearchParams } from 'react-router-dom'; import { RotateCw } from 'lucide-react'; import qs from 'qs'; @@ -27,6 +27,13 @@ const Home = () => { ...qs.parse(new URLSearchParams(window.location.search).toString()), }); + useEffect(() => { + const storedSearchParams = localStorage.getItem('searchParams'); + if (storedSearchParams) { + setSearchParams(new URLSearchParams(storedSearchParams)); + } + }, []); + const [, setSearch] = useThrottle( { throttle: 400, @@ -47,6 +54,7 @@ const Home = () => { setFilterData(initialFilterData); setSearchParams(''); refresh(); + localStorage.removeItem('searchParams'); }, [refresh, setSearch, setSearchParams]); const hasMore = useMemo( @@ -62,6 +70,7 @@ const Home = () => { skipNulls: true, }); setSearchParams(searchQuery); + localStorage.setItem('searchParams', JSON.stringify(searchQuery)); refresh({ params: { search: searchQuery, diff --git a/src/pages/Home/components/ShelterListView/ShelterListView.tsx b/src/pages/Home/components/ShelterListView/ShelterListView.tsx index ec57fc7b..98c9eb2f 100644 --- a/src/pages/Home/components/ShelterListView/ShelterListView.tsx +++ b/src/pages/Home/components/ShelterListView/ShelterListView.tsx @@ -36,7 +36,10 @@ const ShelterListView = React.forwardRef( return (

- Abrigos disponíveis ({count}) + {searchParams.toString() + ? `Abrigos encontrados (${count})` + : `Total de abrigos (${count})` + }