Skip to content

Commit f9e5db4

Browse files
authoredMar 26, 2025··
Merge pull request #6 from DaraghD/search
initial logic for search page
2 parents cdaff08 + 502d1bc commit f9e5db4

File tree

5 files changed

+74
-1719
lines changed

5 files changed

+74
-1719
lines changed
 

‎frontend/package-lock.json

+5-58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎frontend/src/App.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import ProductView from "./_root/pages/ProductView";
1111
import Profile from "@/_root/pages/Profile.tsx";
1212
import ProductListing from "./_root/pages/ProductListing";
1313
import { Toaster } from "./components/ui/sonner";
14+
import Products from "./_root/pages/Search";
1415

1516
const App = () => {
1617
const location = useLocation();
@@ -29,6 +30,7 @@ const App = () => {
2930
<Route element={<AuthLayout />}>
3031
<Route path="/sign-in" element={<SignInForm />} />
3132
<Route path="/sign-up" element={<SignUpForm />} />
33+
<Route path="/search" element={<Products />} />
3234
<Route
3335
path="/business-sign-up"
3436
element={<BusinessSignUpForm />}

‎frontend/src/_root/pages/Search.tsx

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { useEffect, useState } from "react";
2+
3+
type Product = {
4+
id: number;
5+
name: string;
6+
};
7+
8+
const Products = () => {
9+
const [products, setProducts] = useState<Product[]>([]);
10+
const [searchTerm, setSearchTerm] = useState("");
11+
12+
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
13+
event.preventDefault();
14+
}
15+
16+
useEffect(() => {
17+
const fetchProducts = async () => {
18+
try {
19+
const response = await fetch("http://localhost:8080/api/products");
20+
const data = await response.json();
21+
setProducts(data);
22+
}
23+
catch(error){
24+
console.error("Error fetching products", error);
25+
}
26+
}
27+
fetchProducts();
28+
},[]);
29+
30+
const filteredProducts = products.filter((product) =>
31+
product.name.toLowerCase().includes(searchTerm.toLowerCase())
32+
);
33+
34+
return(
35+
<div>
36+
<form onSubmit={handleSubmit}>
37+
<label> Search For Services
38+
<input type="text"
39+
value = {searchTerm}
40+
onChange={(e) => setSearchTerm(e.target.value)}
41+
/>
42+
</label>
43+
<input type="submit" />
44+
</form>
45+
46+
47+
<ul>
48+
{filteredProducts.map((product) => (
49+
<li key = {product.id}>
50+
<div>
51+
<p>{product.name}</p>
52+
</div>
53+
</li>
54+
))}
55+
</ul>
56+
</div>
57+
);
58+
};
59+
60+
export default Products;

‎node_modules/.package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package-lock.json

+1-1,661
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.