Use existing switch component for general filter content

This commit is contained in:
Nicolas Mowen 2024-04-19 14:54:51 -06:00
parent 57873b90c0
commit df1a10294c

View File

@ -593,30 +593,17 @@ export function GeneralFilterContent({
<DropdownMenuSeparator /> <DropdownMenuSeparator />
<div className="my-2.5 flex flex-col gap-2.5"> <div className="my-2.5 flex flex-col gap-2.5">
{allLabels.map((item) => ( {allLabels.map((item) => (
<div className="flex justify-between items-center"> <FilterSwitch
<Label label={item.replaceAll("_", " ")}
className="w-full mx-2 text-primary capitalize cursor-pointer" isChecked={currentLabels?.includes(item) ?? false}
htmlFor={item}
>
{item.replaceAll("_", " ")}
</Label>
<Switch
key={item}
className="ml-1"
id={item}
checked={currentLabels?.includes(item) ?? false}
onCheckedChange={(isChecked) => { onCheckedChange={(isChecked) => {
if (isChecked) { if (isChecked) {
const updatedLabels = currentLabels const updatedLabels = currentLabels ? [...currentLabels] : [];
? [...currentLabels]
: [];
updatedLabels.push(item); updatedLabels.push(item);
setCurrentLabels(updatedLabels); setCurrentLabels(updatedLabels);
} else { } else {
const updatedLabels = currentLabels const updatedLabels = currentLabels ? [...currentLabels] : [];
? [...currentLabels]
: [];
// can not deselect the last item // can not deselect the last item
if (updatedLabels.length > 1) { if (updatedLabels.length > 1) {
@ -626,7 +613,6 @@ export function GeneralFilterContent({
} }
}} }}
/> />
</div>
))} ))}
</div> </div>
</div> </div>