@@ -14,6 +14,7 @@ import ContentBlocks from "./ContentBlocks";
1414import ArrowDown from "./icons/ArrowDown" ;
1515import FilterIcon from "./icons/FilterIcon" ;
1616import Spinner from "./icons/Spinner" ;
17+ import CoachSearch from "./CoachSearch" ;
1718import CoachCard from "./CoachCard" ;
1819import ContentfulRichText from "./ContentfulRichText" ;
1920import type { EmailTemplate } from "~/utils/contentful" ;
@@ -52,15 +53,23 @@ export default function SpeakingTimeContent({
5253 const submit = useSubmit ( ) ;
5354 const formRef = useRef < HTMLFormElement > ( null ) ;
5455 const { t } = useTranslation ( "searchingCoach" ) ;
56+ const [ isActive , setIsActive ] = useState ( false ) ;
57+ var timeout : NodeJS . Timeout ;
5558
5659 const handleChange = ( ) => {
5760 if ( formRef ) {
58- submit ( formRef . current , { replace : true , preventScrollReset : true } ) ;
61+ // not the best solution as the tags now will timeout for 300ms as well - but with the onchange on the form I could not find another way
62+ // to debounce the search input to not sent a request for each input .. happy for suggestions
63+ clearTimeout ( timeout ) ;
64+ timeout = setTimeout (
65+ ( ) =>
66+ submit ( formRef . current , { replace : true , preventScrollReset : true } ) ,
67+ 300 ,
68+ ) ;
5969 }
6070 } ;
6171 const state = useNavigation ( ) ;
6272
63- const [ isActive , setIsActive ] = useState ( false ) ;
6473 // sort tags to ensure the "quick response" one is always the first in the array
6574 tags . unshift (
6675 tags . splice (
@@ -76,31 +85,31 @@ export default function SpeakingTimeContent({
7685 return (
7786 < div >
7887 < ContentBlocks content = { page . fields . content } locale = { locale } />
79- < details open = { true } className = "mx-auto max-w-7xl py-8 px-4" >
80- < summary
81- className = "inline-flex cursor-pointer items-center hover:text-vsp-500"
82- onClick = { ( ) => setIsActive ( ! isActive ) }
83- >
84- < FilterIcon />
85- < h5 className = "inline-block px-4 text-xl" id = "details-filter" >
86- { t ( "filter.showFilter" ) }
87- </ h5 >
88- < div
89- className = { `transition-transform hover:text-vsp-500 ${
90- isActive ? "rotate-180" : "rotate-0"
91- } `}
88+ < Form
89+ onChange = { handleChange }
90+ ref = { formRef }
91+ method = "get"
92+ id = "filter-form"
93+ className = "bg-slate-100"
94+ >
95+ < details open = { false } className = "mx-auto max-w-7xl pt-6 px-4" >
96+ < summary
97+ className = "inline-flex cursor-pointer items-center hover:text-vsp-500"
98+ onClick = { ( ) => setIsActive ( ! isActive ) }
9299 >
93- < ArrowDown />
94- </ div >
95- </ summary >
100+ < FilterIcon />
101+ < h5 className = "inline-block px-4 text-xl" id = "details-filter" >
102+ { t ( "filter.showFilter" ) }
103+ </ h5 >
104+ < div
105+ className = { `transition-transform hover:text-vsp-500 ${
106+ isActive ? "rotate-180" : "rotate-0"
107+ } `}
108+ >
109+ < ArrowDown />
110+ </ div >
111+ </ summary >
96112
97- < Form
98- onChange = { handleChange }
99- ref = { formRef }
100- method = "get"
101- id = "filter-form"
102- className = "flex flex-col gap-2"
103- >
104113 < fieldset className = "mt-8" >
105114 < legend className = "mb-4 inline-block text-xl" >
106115 { t ( "filter.language" ) }
@@ -178,11 +187,15 @@ export default function SpeakingTimeContent({
178187 </ button >
179188 </ noscript >
180189 </ div >
181- </ Form >
182- </ details >
183- < div className = "text-m mx-auto max-w-7xl py-4 px-4 font-semibold text-slate-700" >
184- { coachesAmount ? `${ coachesAmount } ${ t ( "result" ) } ` : t ( "noResult" ) }
185- </ div >
190+ </ details >
191+ < div className = "py-6 px-4 max-w-7xl mx-auto flex justify-end lg:justify-between items-center flex-wrap" >
192+ < CoachSearch />
193+ < div className = "text-m font-semibold text-slate-700" >
194+ { coachesAmount ? `${ coachesAmount } ${ t ( "result" ) } ` : t ( "noResult" ) }
195+ </ div >
196+ </ div >
197+ </ Form >
198+
186199 < div className = "relative" >
187200 { state . state === "loading" && (
188201 < div className = "absolute inset-0 z-50 flex items-start justify-center bg-white bg-opacity-50" >
0 commit comments