Skip to content

Commit

Permalink
refactor: individual clear filter
Browse files Browse the repository at this point in the history
  • Loading branch information
leapalazzolo committed Jan 8, 2024
1 parent 179a220 commit fb00cff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
12 changes: 11 additions & 1 deletion assets/icons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import * as React from "react";
import { IconSvgProps } from "@/types/index";

export const CircledCross = ({ size = 24,
width,
height,
...props }: IconSvgProps) => (
<svg
height={size || height}
viewBox="0 0 24 24"
width={size || width}
{...props}>
<path d="M12 2a10 10 0 1010 10A10.016 10.016 0 0012 2zm3.36 12.3a.754.754 0 010 1.06.748.748 0 01-1.06 0l-2.3-2.3-2.3 2.3a.748.748 0 01-1.06 0 .754.754 0 010-1.06l2.3-2.3-2.3-2.3A.75.75 0 019.7 8.64l2.3 2.3 2.3-2.3a.75.75 0 011.06 1.06l-2.3 2.3z" fill="currentColor"></path> </svg>
)
export const HeartFilledIcon = ({
size = 24,
width,
Expand Down
6 changes: 5 additions & 1 deletion components/filters/select-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Select, SelectItem } from "@nextui-org/select";
import { FilterOption } from "@/types/filters";
import { createUrl } from "@/utils/url";
import Emoji from "../emoji";
import { CircledCross } from "@/assets/icons";

interface ISelectFilterProps {
placeholder: string;
Expand Down Expand Up @@ -39,7 +40,9 @@ export const SelectFilter = ({
router.replace(optionUrl, { scroll: false });

};

const resetFilter = () => {
handleSelectionChange("")
}
return (
<Select
aria-label={`Select Filter ${placeholder}`}
Expand All @@ -49,6 +52,7 @@ export const SelectFilter = ({
placeholder={placeholder}
selectionMode="single"
startContent={<Emoji emoji={mainEmoji} className="text-sm" />}
endContent={selectedKey && <CircledCross className="z-10 appearance-none outline-none select-none transition-opacity opacity-70 hover:opacity-100 cursor-pointer active:opacity-disabled tap-highlight-transparent text-large" onClick={resetFilter} />}
selectedKeys={selectedKey ? new Set([selectedKey]) : new Set()}
onSelectionChange={handleSelectionChange}
>
Expand Down
21 changes: 3 additions & 18 deletions components/filters/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,10 @@ const Toolbar = ({ searchParams }: IToolbarProps) => {
/>
</div>

{
numberOfFilters > 0 &&
<div className="flex justify-left items-stretch gap-4">
{numberOfFilters > 1 && (
<ClearFilters onClear={clearAllFilters} value="All filters" />
)}

{searchParams?.languages && (
<ClearFilters onClear={clearLanguagesFilter} value={searchParams.languages} param="languages" />
)}
{searchParams?.interests && (
<ClearFilters onClear={clearInterestsFilter} value={searchParams.interests} param="interests" />
)}
{searchParams?.projects && (
<ClearFilters onClear={clearProjectsFilter} value={searchParams.projects} param="projects" />
)}
{numberOfFilters > 1 && (
<ClearFilters onClear={clearAllFilters} value="All filters" />
)}
</div>

}
</>
);
};
Expand Down

0 comments on commit fb00cff

Please sign in to comment.