-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/add catalog query filter values and corresponding ui logic (#110
) * add query filter values and corresponding ui logic * simplify infinite scroll logic * fix query filters
- Loading branch information
1 parent
57a5bb1
commit a989afa
Showing
14 changed files
with
361 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use client"; | ||
|
||
import { useHeroContext } from "../contexts/HeroContext"; | ||
import GenericPopover from "../ui/Popover"; | ||
import useFilterQueryParams from "./useFilterQueryParams"; | ||
import FilterOptionButtons from "./FilterOptionButtons"; | ||
|
||
function Trigger({ defaultValue }: { defaultValue: string }) { | ||
return <div>{defaultValue}</div>; | ||
} | ||
|
||
export default function Category() { | ||
const { dictionary } = useHeroContext(); | ||
const { | ||
defaultValue: defaultCategory, | ||
handleFilterChange: handleCategoryChange, | ||
} = useFilterQueryParams("category"); | ||
const { | ||
defaultValue: defaultGender, | ||
handleFilterChange: handleGenderChange, | ||
} = useFilterQueryParams("gender"); | ||
|
||
return ( | ||
<GenericPopover | ||
contentProps={{ | ||
side: "bottom", | ||
align: "start", | ||
}} | ||
title="categories" | ||
openElement={ | ||
<Trigger | ||
defaultValue={`${defaultCategory || "all categories"} / ${defaultGender || "all genders"}`} | ||
/> | ||
} | ||
> | ||
<div className="mb-8"> | ||
<FilterOptionButtons | ||
defaultOptionText="all" | ||
defaultValue={defaultCategory || ""} | ||
handleFilterChange={handleCategoryChange} | ||
values={dictionary?.categories || []} | ||
/> | ||
</div> | ||
|
||
<div className="mb-8"> | ||
<div className="mb-4">gender</div> | ||
<FilterOptionButtons | ||
defaultValue={defaultGender || ""} | ||
handleFilterChange={handleGenderChange} | ||
values={dictionary?.genders || []} | ||
defaultOptionText="all" | ||
/> | ||
</div> | ||
</GenericPopover> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"use client"; | ||
|
||
import { | ||
common_Category, | ||
common_OrderFactors, | ||
common_Size, | ||
common_SortFactors, | ||
common_Genders, | ||
} from "@/api/proto-http/frontend"; | ||
import { cn } from "@/lib/utils"; | ||
|
||
export default function FilterOptionButtons({ | ||
handleFilterChange, | ||
defaultValue, | ||
defaultOptionText, | ||
values, | ||
}: { | ||
handleFilterChange: (term?: string) => void; | ||
defaultValue: string; | ||
defaultOptionText?: string; | ||
values: | ||
| common_Category[] | ||
| common_OrderFactors[] | ||
| common_SortFactors[] | ||
| common_Size[] | ||
| common_Genders[]; | ||
}) { | ||
return ( | ||
<> | ||
{defaultOptionText && ( | ||
<button | ||
onClick={() => handleFilterChange()} | ||
className={cn("block", { underline: !defaultValue })} | ||
> | ||
{defaultOptionText} | ||
</button> | ||
)} | ||
{values.map((factor) => ( | ||
<button | ||
onClick={() => handleFilterChange(factor.id + "")} | ||
className={cn("block", { | ||
underline: factor.id + "" === defaultValue, | ||
})} | ||
key={factor.id} | ||
> | ||
{factor.name} | ||
</button> | ||
))} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"use client"; | ||
|
||
import { useHeroContext } from "../contexts/HeroContext"; | ||
import GenericPopover from "../ui/Popover"; | ||
import useFilterQueryParams from "./useFilterQueryParams"; | ||
import FilterOptionButtons from "./FilterOptionButtons"; | ||
|
||
function Trigger({ defaultValue }: { defaultValue: string }) { | ||
return ( | ||
<div> | ||
order <span className="underline">{defaultValue}</span> | ||
</div> | ||
); | ||
} | ||
|
||
export default function Order() { | ||
const { dictionary } = useHeroContext(); | ||
const { defaultValue, handleFilterChange } = useFilterQueryParams("order"); | ||
|
||
return ( | ||
<GenericPopover | ||
contentProps={{ | ||
side: "bottom", | ||
align: "end", | ||
}} | ||
title="order_by" | ||
openElement={<Trigger defaultValue={defaultValue || ""} />} | ||
> | ||
<FilterOptionButtons | ||
defaultOptionText="none" | ||
defaultValue={defaultValue || ""} | ||
handleFilterChange={handleFilterChange} | ||
values={dictionary?.orderFactors || []} | ||
/> | ||
</GenericPopover> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use client"; | ||
import { useHeroContext } from "../contexts/HeroContext"; | ||
import GenericPopover from "../ui/Popover"; | ||
import useFilterQueryParams from "./useFilterQueryParams"; | ||
import FilterOptionButtons from "./FilterOptionButtons"; | ||
|
||
function Trigger({ defaultValue }: { defaultValue: string }) { | ||
return ( | ||
<div> | ||
size <span className="underline">{defaultValue}</span> | ||
</div> | ||
); | ||
} | ||
|
||
export default function Size() { | ||
const { dictionary } = useHeroContext(); | ||
const { defaultValue, handleFilterChange } = useFilterQueryParams("size"); | ||
|
||
return ( | ||
<GenericPopover | ||
contentProps={{ | ||
side: "bottom", | ||
align: "end", | ||
}} | ||
title="size" | ||
openElement={<Trigger defaultValue={defaultValue || ""} />} | ||
> | ||
<FilterOptionButtons | ||
defaultValue={defaultValue || ""} | ||
handleFilterChange={handleFilterChange} | ||
values={dictionary?.sizes || []} | ||
defaultOptionText="all sizes" | ||
/> | ||
</GenericPopover> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"use client"; | ||
|
||
import GenericPopover from "@/components/ui/Popover"; | ||
import { useHeroContext } from "../contexts/HeroContext"; | ||
import useFilterQueryParams from "./useFilterQueryParams"; | ||
import FilterOptionButtons from "./FilterOptionButtons"; | ||
|
||
function Trigger({ defaultValue }: { defaultValue: string }) { | ||
return ( | ||
<div> | ||
sort_by <span className="underline">{defaultValue}</span> | ||
</div> | ||
); | ||
} | ||
|
||
export default function Sort() { | ||
const { dictionary } = useHeroContext(); | ||
const { defaultValue, handleFilterChange } = useFilterQueryParams("sort"); | ||
|
||
return ( | ||
<GenericPopover | ||
contentProps={{ | ||
side: "bottom", | ||
align: "end", | ||
}} | ||
title="order_by" | ||
openElement={<Trigger defaultValue={defaultValue || ""} />} | ||
> | ||
<FilterOptionButtons | ||
defaultValue={defaultValue || ""} | ||
handleFilterChange={handleFilterChange} | ||
values={dictionary?.sortFactors || []} | ||
defaultOptionText="none" | ||
/> | ||
</GenericPopover> | ||
); | ||
} |
Oops, something went wrong.