11import "../../style/CardList.css" ;
22import "./CocktailList.css" ;
33import { ResponseData } from "../interfaces" ;
4- import getCotails from "../../../services/cotails-api" ;
4+ import getData from "../../../services/cotails-api" ;
55import { useQuery } from "@tanstack/react-query" ;
66import CocktailCard from "../CocktailCard/CocktailCard" ;
77import PageSwitcher from "../../../components/PageSwitcher/PageSwitcher" ;
88import Loader from "../../../components/Loader/Loader" ;
99import { Outlet , useLocation } from "react-router-dom" ;
10+ import { Button } from "@/components/ui/button" ;
11+ import useCustomSearchParams from "@/hooks/useCustomSearchParams" ;
1012
1113async function getCards ( { queryKey } : { queryKey : [ string , string ] } ) {
12- const [ _key , search ] = queryKey ;
13- const response = await getCotails ( `/cocktails${ search } ` ) ;
14+ const [ , search ] = queryKey ;
15+ const response = await getData ( `/cocktails${ search } ` ) ;
1416
1517 return response ;
1618}
1719
1820function CocktailList ( ) {
21+ const [ , setSearchParams ] = useCustomSearchParams ( ) ;
1922 const location = useLocation ( ) ;
2023
2124 const { search } = location ;
2225
23- const { data, isLoading, error } = useQuery ( [ "cocktails" , search ] , getCards ) ;
26+ const { data, isLoading, error } = useQuery ( [ "cocktails" , search ] , getCards , {
27+ staleTime : 5 * 60 * 1000 ,
28+ cacheTime : 15 * 60 * 1000 ,
29+ enabled : ! ! search ,
30+ retry : 2 ,
31+ refetchOnWindowFocus : false ,
32+ } ) ;
2433
2534 if ( error ) return < p > Error loading data.</ p > ;
2635
2736 const cards = data as ResponseData ;
2837
2938 const isNoData = cards ?. data ?. length === 0 ;
3039
40+ const handleResetFilter = ( ) => {
41+ setSearchParams ( { } ) ;
42+ } ;
43+
3144 return (
3245 < >
3346 { isLoading ? (
@@ -41,8 +54,11 @@ function CocktailList() {
4154 ) }
4255
4356 { isNoData && ! isLoading && (
44- < div className = "rest -filter" >
57+ < div className = "reset -filter" >
4558 < h3 className = "emty-data" > No data available for this request</ h3 >
59+ < Button className = "reset-filters-btn" onClick = { handleResetFilter } >
60+ Reset Filter
61+ </ Button >
4662 </ div >
4763 ) }
4864 < PageSwitcher metaData = { cards ?. meta || null } />
0 commit comments