MCPcopy
hub / github.com/adrianhajdin/project_next13_car_showcase / updateSearchParams

Function updateSearchParams

components/Searchbar.tsx:37–59  ·  view source on GitHub ↗
(model: string, manufacturer: string)

Source from the content-addressed store, hash-verified

35 };
36
37 const updateSearchParams = (model: string, manufacturer: string) => {
38 // Create a new URLSearchParams object using the current URL search parameters
39 const searchParams = new URLSearchParams(window.location.search);
40
41 // Update or delete the 'model' search parameter based on the 'model' value
42 if (model) {
43 searchParams.set("model", model);
44 } else {
45 searchParams.delete("model");
46 }
47
48 // Update or delete the 'manufacturer' search parameter based on the 'manufacturer' value
49 if (manufacturer) {
50 searchParams.set("manufacturer", manufacturer);
51 } else {
52 searchParams.delete("manufacturer");
53 }
54
55 // Generate the new pathname with the updated search parameters
56 const newPathname = `${window.location.pathname}?${searchParams.toString()}`;
57
58 router.push(newPathname);
59 };
60
61 return (
62 <form className='searchbar' onSubmit={handleSearch}>

Callers 3

handleNavigationFunction · 0.70
handleUpdateParamsFunction · 0.70
handleSearchFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected