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,40 +593,26 @@ 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} onCheckedChange={(isChecked) => {
> if (isChecked) {
{item.replaceAll("_", " ")} const updatedLabels = currentLabels ? [...currentLabels] : [];
</Label>
<Switch
key={item}
className="ml-1"
id={item}
checked={currentLabels?.includes(item) ?? false}
onCheckedChange={(isChecked) => {
if (isChecked) {
const updatedLabels = currentLabels
? [...currentLabels]
: [];
updatedLabels.push(item); updatedLabels.push(item);
setCurrentLabels(updatedLabels);
} else {
const updatedLabels = currentLabels ? [...currentLabels] : [];
// can not deselect the last item
if (updatedLabels.length > 1) {
updatedLabels.splice(updatedLabels.indexOf(item), 1);
setCurrentLabels(updatedLabels); setCurrentLabels(updatedLabels);
} else {
const updatedLabels = currentLabels
? [...currentLabels]
: [];
// can not deselect the last item
if (updatedLabels.length > 1) {
updatedLabels.splice(updatedLabels.indexOf(item), 1);
setCurrentLabels(updatedLabels);
}
} }
}} }
/> }}
</div> />
))} ))}
</div> </div>
</div> </div>