@@ -9,6 +9,7 @@ import { EmbalseSearchModel } from "./embalse-search.vm";
99import { getFilteredEmbalses as getFilteredEmbalsesBusiness } from "./embalse-search.business" ;
1010import { FilteredList } from "./components/filtered-list" ;
1111import { Input } from "./components/input" ;
12+ import { RecentSearches , useRecentSearches } from "./components" ;
1213
1314interface Props {
1415 embalses : Embalse [ ] ;
@@ -22,6 +23,7 @@ export const EmbalseSearch: React.FC<Props> = (props) => {
2223 > ( [ ] ) ;
2324 const [ isNavigating , setIsNavigating ] = useState < boolean > ( false ) ;
2425 const [ inputValue , setInputValue ] = useState < string > ( "" ) ;
26+ const { addNewEmbalseToLatestSearchCollection, recentSearches } = useRecentSearches ( ) ;
2527
2628 const getFilteredEmbalses = ( inputValue : string ) : EmbalseSearchModel [ ] => {
2729 return getFilteredEmbalsesBusiness ( inputValue , embalses ) ;
@@ -42,12 +44,14 @@ export const EmbalseSearch: React.FC<Props> = (props) => {
4244 onSelectedItemChange : ( { selectedItem } ) => {
4345 if ( selectedItem ) {
4446 setIsNavigating ( true ) ;
47+ addNewEmbalseToLatestSearchCollection ( selectedItem ) ;
4548 router . push ( `/embalse/${ selectedItem . slug } ` ) ;
4649 }
4750 } ,
4851 } ) ;
4952
50- const showNoResults = inputValue . length > 0 && filteredEmbalses . length === 0 && ! isNavigating ;
53+ const showNoResults =
54+ inputValue . length > 0 && filteredEmbalses . length === 0 && ! isNavigating ;
5155
5256 return (
5357 < div className = "relative flex flex-1 flex-col overflow-hidden p-8" >
@@ -57,15 +61,19 @@ export const EmbalseSearch: React.FC<Props> = (props) => {
5761 > </ div >
5862 < div className = "flex grow flex-col items-center justify-center" >
5963 < section
60- className = "bg-base-100 absolute flex max-w-10/12 flex-col gap-8 rounded-xl p-8 shadow-lg"
64+ className = "bg-base-100 absolute flex max-w-10/12 flex-col gap-3 rounded-xl p-8 shadow-lg"
6165 aria-labelledby = "search-title"
6266 >
6367 < div className = "text-center" >
6468 < h2 id = "search-title" className = "font-bold" >
6569 Embalses
6670 </ h2 >
6771 </ div >
68-
72+ < div >
73+ < p className = "text-sm" >
74+ Encuentra toda la información disponible de los embalses de España
75+ </ p >
76+ </ div >
6977 < div className = "flex flex-col gap-4" >
7078 < div className = "relative" role = "search" >
7179 < Input getInputProps = { getInputProps } />
@@ -78,13 +86,12 @@ export const EmbalseSearch: React.FC<Props> = (props) => {
7886 />
7987 { showNoResults && < NoResult inputValue = { inputValue } /> }
8088 </ div >
81- < div >
82- < p className = "text-sm" >
83- Encuentra toda la información disponible de los embalses de
84- España
85- </ p >
86- </ div >
8789 </ div >
90+ { recentSearches . length > 0 && (
91+ < div className = "mt-5" >
92+ < RecentSearches searches = { recentSearches } />
93+ </ div >
94+ ) }
8895 </ section >
8996 </ div >
9097 </ div >
0 commit comments