Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tags to video list #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/app/(app)/uploads/components/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TranscriptionPreview } from '@/components/transcription-preview'
import { CopyButton } from '@/components/copy-button'
import { formatBytes } from '@/utils/format-bytes'
import Link from 'next/link'
import { Badge } from '@/components/ui/badge'

dayjs.extend(relativeTime)

Expand All @@ -23,13 +24,29 @@ export const columns: ColumnDef<Video>[] = [
cell: ({ row }) => {
return (
<div className="flex flex-col">
<Link
href={`/videos/${row.original.id}`}
prefetch={false}
className="text-violet-500 hover:underline dark:text-violet-300"
>
{row.original.title}
</Link>
<div className="flex items-center gap-2">
<Link
href={`/videos/${row.original.id}`}
prefetch={false}
className="text-violet-500 hover:underline dark:text-violet-300"
>
{row.original.title}
</Link>

{row.original.tags && (
<div className="flex gap-1 py-0.5">
{row.original.tags?.map((tag) => (
<Badge
variant="secondary"
key={tag.id}
className="pointer-events-none rounded-sm px-1 font-normal"
>
{tag.slug}
</Badge>
))}
</div>
)}
</div>
<span className="text-xs text-muted-foreground">
{row.original.id}
</span>
Expand Down
9 changes: 9 additions & 0 deletions src/app/(app)/uploads/data/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export const videoSchema = z.object({
id: z.string(),
})
.optional(),
tags: z
.array(
z.object({
id: z.string().uuid(),
slug: z.string(),
createdAt: z.coerce.date(),
}),
)
.optional(),
})

export type Video = z.infer<typeof videoSchema>
3 changes: 2 additions & 1 deletion src/app/(app)/uploads/video-list.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { useCallback, useEffect, useState } from 'react'
import { useState } from 'react'
import { useQuery } from '@tanstack/react-query'
import { DataTable } from './components/data-table'
import axios from 'axios'
Expand All @@ -20,6 +20,7 @@ export function VideoList() {
params: {
pageIndex,
pageSize,
tags: true,
},
})

Expand Down
4 changes: 4 additions & 0 deletions src/app/api/videos/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export async function GET(request: Request) {
.default(10)
.parse(searchParams.get('pageSize'))

const tags = z.coerce.boolean().default(false).parse(searchParams.get('tags'))

try {
const [videos, count] = await Promise.all([
prisma.video.findMany({
Expand All @@ -24,6 +26,8 @@ export async function GET(request: Request) {
id: true,
},
},

tags,
},
orderBy: {
createdAt: 'desc',
Expand Down