Fix web routing

This commit is contained in:
augmentedpotato
2026-04-02 08:54:24 -06:00
parent 6afda8e7b8
commit 3ee59521fd
12 changed files with 407 additions and 252 deletions

View File

@@ -17,9 +17,6 @@ export default function ProductDetailPage() {
if (!id) {
return;
}
setLoading(true);
setError(null);
fetch(`${API_BASE}/api/v1/products/${id}`)
.then((res) => {

View File

@@ -11,16 +11,11 @@ export default function ProductsPage() {
const [error, setError] = useState(null);
const [search, setSearch] = useState("");
const [query, setQuery] = useState("");
const [page, setPage] = useState(0);
const [totalPages, setTotalPages] = useState(0);
const PAGE_SIZE = 12;
const PAGE_SIZE = 200;
useEffect(() => {
setLoading(true);
setError(null);
const params = new URLSearchParams({ page, size: PAGE_SIZE, sort: "prodId,asc" });
const params = new URLSearchParams({ page: 0, size: PAGE_SIZE, sort: "prodId,asc" });
if (query) {
params.set("q", query);
}
@@ -35,15 +30,15 @@ export default function ProductsPage() {
})
.then((data) => {
setProducts(data.content ?? []);
setTotalPages(data.totalPages ?? 0);
})
.catch((err) => setError(err.message))
.finally(() => setLoading(false));
}, [page, query]);
}, [query]);
function handleSearch(e) {
e.preventDefault();
setPage(0);
setLoading(true);
setError(null);
setQuery(search.trim());
}
@@ -70,7 +65,7 @@ export default function ProductsPage() {
<button
className="adopt-clear-btn"
type="button"
onClick={() => { setSearch(""); setQuery(""); setPage(0); }}
onClick={() => { setLoading(true); setError(null); setSearch(""); setQuery(""); }}
>
Clear
</button>
@@ -108,25 +103,6 @@ export default function ProductsPage() {
</div>
)}
{!loading && totalPages > 1 && (
<div className="adopt-pagination">
<button
className="pagination-btn"
disabled={page === 0}
onClick={() => setPage((p) => p - 1)}
>
Prev
</button>
<span className="pagination-info">Page {page + 1} of {totalPages}</span>
<button
className="pagination-btn"
disabled={page >= totalPages - 1}
onClick={() => setPage((p) => p + 1)}
>
Next
</button>
</div>
)}
</section>
</main>
);