-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 content by watched, watching & unw…
…atched videos and optimised Admin Panel (#1486) * feat:Added Filter Button to filter out watched, watching & unwatched content * feat:Added Filter Button and enhanced admin panel * few fixes * final fixes to the new features * final fixes to the new features --------- Co-authored-by: Sargam <[email protected]>
- Loading branch information
1 parent
f2596bb
commit 99dd0fa
Showing
15 changed files
with
369 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import db from '@/db'; | ||
import { getServerSession } from 'next-auth'; | ||
import { authOptions } from '@/lib/auth'; | ||
import { z } from 'zod'; | ||
|
||
const requestBodySchema = z.object({ | ||
contentId: z.number(), | ||
duration: z.number(), | ||
}); | ||
|
||
export async function POST(req: NextRequest) { | ||
const parseResult = requestBodySchema.safeParse(await req.json()); | ||
|
||
if (!parseResult.success) { | ||
return NextResponse.json( | ||
{ error: parseResult.error.message }, | ||
{ status: 400 }, | ||
); | ||
} | ||
const { contentId, duration } = parseResult.data; | ||
const session = await getServerSession(authOptions); | ||
if (!session || !session?.user) { | ||
return NextResponse.json({}, { status: 401 }); | ||
} | ||
|
||
const updatedRecord = await db.videoMetadata.upsert({ | ||
where: { | ||
contentId: Number(contentId), | ||
}, | ||
create: { | ||
contentId: Number(contentId), | ||
duration: Number(duration), | ||
}, | ||
update: { | ||
duration, | ||
}, | ||
}); | ||
|
||
return NextResponse.json(updatedRecord); | ||
} |
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,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
Oops, something went wrong.