-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:Added Filter Button to filter out watched, watching & unwatched …
…content
- Loading branch information
1 parent
6a49a64
commit 393884e
Showing
7 changed files
with
217 additions
and
53 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 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,82 @@ | ||
'use client'; | ||
import React, { useState, forwardRef } from 'react'; | ||
import { Check, ChevronsUpDown } from 'lucide-react'; | ||
import { cn } from '@/lib/utils'; | ||
import { Button } from '@/components/ui/button'; | ||
import { useRecoilState } from 'recoil'; | ||
import { selectFilter } from '@/store/atoms/filterContent'; | ||
import { | ||
Command, | ||
CommandGroup, | ||
CommandItem, | ||
CommandList, | ||
} from '@/components/ui/command'; | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from '@/components/ui/popover'; | ||
|
||
const allFilters = [ | ||
{ value: 'all', label: 'ALL' }, | ||
{ value: 'unwatched', label: 'Unwatched' }, | ||
{ value: 'watched', label: 'Watched' }, | ||
{ value: 'watching', label: 'Watching' }, | ||
]; | ||
|
||
type FilterContentProps = { | ||
// Add any other props here if needed | ||
className?: string; | ||
}; | ||
|
||
export const FilterContent = forwardRef<HTMLDivElement, FilterContentProps>( | ||
(props, ref) => { | ||
const [open, setOpen] = useState(false); | ||
const [value, setValue] = useRecoilState(selectFilter); | ||
|
||
return ( | ||
<Popover open={open} onOpenChange={setOpen}> | ||
<PopoverTrigger asChild> | ||
<Button | ||
variant="outline" | ||
role="combobox" | ||
aria-expanded={open} | ||
className={`w-fit gap-2 ${props.className || ''}`} | ||
> | ||
{value | ||
? allFilters.find((filters) => filters.value === value)?.label | ||
: 'Filter'} | ||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" /> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent className="z-[99999] w-fit p-0" ref={ref}> | ||
<Command> | ||
<CommandList> | ||
<CommandGroup> | ||
{allFilters.map((filters) => ( | ||
<CommandItem | ||
key={filters.value} | ||
value={filters.value} | ||
className={`px-4 ${props.className || ''}`} | ||
onSelect={(currentValue) => { | ||
setValue(currentValue === value ? '' : currentValue); | ||
setOpen(false); | ||
}} | ||
> | ||
<Check | ||
className={cn( | ||
'mr-2 h-4 w-4', | ||
value === filters.value ? 'opacity-100' : 'opacity-0', | ||
)} | ||
/> | ||
{filters.label} | ||
</CommandItem> | ||
))} | ||
</CommandGroup> | ||
</CommandList> | ||
</Command> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
}, | ||
); |
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 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,6 @@ | ||
import { atom } from 'recoil'; | ||
|
||
export const selectFilter = atom({ | ||
key: 'selectFilter', | ||
default: '', | ||
}); |