-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from kudos-ink/feat/serach_params_filters
[Feat] Search and filters
- Loading branch information
Showing
22 changed files
with
1,242 additions
and
397 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
This file was deleted.
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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use client"; | ||
import React from "react"; | ||
import { usePathname, useSearchParams } from "next/navigation"; | ||
import { useRouter } from "next/navigation"; | ||
import { Chip } from "@nextui-org/chip"; | ||
import { createUrl } from "@/utils/url"; | ||
|
||
interface IClearFilters { | ||
param?: string; | ||
value: string; | ||
onClear: () => void; | ||
} | ||
|
||
export const ClearFilters = ({ param, value, onClear }: IClearFilters) => { | ||
const router = useRouter(); | ||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
const clearSearchParams = () => { | ||
if (!!param) { | ||
const optionNameLowerCase = param.toLowerCase(); | ||
const optionSearchParams = new URLSearchParams(searchParams.toString()); | ||
optionSearchParams.delete(optionNameLowerCase); | ||
const optionUrl = createUrl(pathname, optionSearchParams); | ||
router.replace(optionUrl); | ||
} else { | ||
router.replace(pathname); | ||
} | ||
onClear(); | ||
}; | ||
return ( | ||
<div className="flex gap-4"> | ||
<Chip variant="solid" onClose={clearSearchParams}> | ||
{value} | ||
</Chip> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ClearFilters; |
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,75 @@ | ||
"use client"; | ||
import React from "react"; | ||
import { usePathname, useSearchParams } from "next/navigation"; | ||
import { useRouter } from "next/navigation"; | ||
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; | ||
mainEmoji: string; | ||
options: FilterOption[]; | ||
selectedKey?: string; | ||
onSelect: (value: string) => void; | ||
} | ||
export const SelectFilter = ({ | ||
placeholder, | ||
mainEmoji, | ||
options, | ||
selectedKey, | ||
onSelect, | ||
}: ISelectFilterProps) => { | ||
const router = useRouter(); | ||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
|
||
const handleSelectionChange = (selection: unknown) => { | ||
const selectedValue = Array.from(selection as Iterable<string>)[0]; | ||
onSelect(selectedValue); | ||
const optionNameLowerCase = placeholder.toLowerCase(); | ||
const optionSearchParams = new URLSearchParams(searchParams.toString()); | ||
if (selectedValue) { | ||
optionSearchParams.set(optionNameLowerCase, selectedValue); | ||
} else { | ||
optionSearchParams.delete(optionNameLowerCase) | ||
} | ||
const optionUrl = createUrl(pathname, optionSearchParams); | ||
router.replace(optionUrl, { scroll: false }); | ||
|
||
}; | ||
const resetFilter = () => { | ||
handleSelectionChange("") | ||
} | ||
return ( | ||
<Select | ||
aria-label={`Select Filter ${placeholder}`} | ||
color="default" | ||
variant="faded" | ||
size="sm" | ||
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} | ||
> | ||
{options.map(({ emoji, label, value }) => { | ||
|
||
return ( | ||
<SelectItem | ||
key={value} | ||
value={value} | ||
startContent={<Emoji emoji={emoji} />} | ||
> | ||
{label} | ||
</SelectItem> | ||
); | ||
})} | ||
</Select> | ||
); | ||
}; | ||
|
||
export default SelectFilter; |
Oops, something went wrong.