support for filtering and updating caliber
This commit is contained in:
@@ -112,6 +112,7 @@ export default function PartsBrowseClient(props: {
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [brandFilter, setBrandFilter] = useState<string[]>([]);
|
||||
const [caliberFilter, setCaliberFilter] = useState<string[]>([]);
|
||||
const [sortBy, setSortBy] = useState<SortOption>("relevance");
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [priceRange, setPriceRange] = useState<{
|
||||
@@ -151,7 +152,10 @@ export default function PartsBrowseClient(props: {
|
||||
if (brandFilter.length)
|
||||
brandFilter.forEach((b) => search.append("brand", b));
|
||||
|
||||
// sort mapping
|
||||
// server search caliber
|
||||
if (caliberFilter.length)
|
||||
caliberFilter.forEach((c) => search.append("caliber", c));
|
||||
|
||||
// sort mapping (Spring-style: sort=field,dir)
|
||||
switch (sortBy) {
|
||||
case "price-asc":
|
||||
@@ -222,6 +226,7 @@ export default function PartsBrowseClient(props: {
|
||||
searchQuery,
|
||||
sortBy,
|
||||
brandFilter,
|
||||
caliberFilter,
|
||||
]);
|
||||
// Reset pagination on filters
|
||||
useEffect(() => {
|
||||
@@ -230,6 +235,7 @@ export default function PartsBrowseClient(props: {
|
||||
partRole,
|
||||
effectivePlatform,
|
||||
brandFilter,
|
||||
caliberFilter,
|
||||
sortBy,
|
||||
searchQuery,
|
||||
priceRange,
|
||||
@@ -252,6 +258,14 @@ export default function PartsBrowseClient(props: {
|
||||
[parts]
|
||||
);
|
||||
|
||||
const availableCalibers = useMemo(
|
||||
() =>
|
||||
Array.from(new Set(parts.map((p: any) => p.caliber)))
|
||||
.filter(Boolean)
|
||||
.sort((a, b) => String(a).localeCompare(String(b))),
|
||||
[parts]
|
||||
);
|
||||
|
||||
const priceBounds = useMemo(() => {
|
||||
const prices = parts
|
||||
.map((p) => p.price)
|
||||
@@ -406,6 +420,9 @@ export default function PartsBrowseClient(props: {
|
||||
availableBrands={availableBrands}
|
||||
brandFilter={brandFilter}
|
||||
setBrandFilter={setBrandFilter}
|
||||
availableCalibers={availableCalibers}
|
||||
caliberFilter={caliberFilter}
|
||||
setCaliberFilter={setCaliberFilter}
|
||||
priceBounds={priceBounds}
|
||||
priceRange={priceRange}
|
||||
setPriceRange={setPriceRange}
|
||||
|
||||
Reference in New Issue
Block a user