Update category table to show number of bookmarks

master
TZGyn 2 years ago
parent 76d406881e
commit 2fc94fc27b
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -1,6 +1,4 @@
import {
bookmarkCategorySchema,
} from '@/types'
import { bookmarkCategoryWithBookmarksSchema } from '@/types'
import { db } from '@/lib/db'
import { cookies } from 'next/headers'
import { getUser } from '@/lib/auth'
@ -17,9 +15,14 @@ export default async function CategoriesPage() {
const data = await db.query.bookmarkCategory.findMany({
where: (bookmarkCategory, { eq }) =>
eq(bookmarkCategory.userId, session_user ? session_user.id : 0),
with: {
bookmark: true,
},
})
const bookmarkCategories = bookmarkCategorySchema.array().parse(data)
const bookmarkCategories = bookmarkCategoryWithBookmarksSchema
.array()
.parse(data)
return (
<div className='flex w-full max-w-4xl flex-row flex-wrap justify-start gap-6'>

@ -10,19 +10,20 @@ import {
Tooltip,
} from '@nextui-org/react'
import { DeleteIcon, EditIcon } from '@/components/icons'
import { BookmarkCategory } from '@/types'
import { BookmarkCategoryWithBookmarks } from '@/types'
import { useRouter } from 'next/navigation'
const columns = [
{ name: 'NAME', uid: 'name' },
{ name: 'BOOKMARK COUNT', uid: 'bookmarkcount' },
{ name: 'ACTIONS', uid: 'actions' },
]
export default function TableComponent({
bookmarkCategories,
}: {
bookmarkCategories: BookmarkCategory[]
bookmarkCategories: BookmarkCategoryWithBookmarks[]
}) {
const router = useRouter()
@ -54,6 +55,7 @@ export default function TableComponent({
{(item) => (
<TableRow key={item.id}>
<TableCell>{item.name}</TableCell>
<TableCell>{item.bookmark.length}</TableCell>
<TableCell>
<div className='relative flex items-center gap-2'>
<Tooltip content='Edit Category'>

Loading…
Cancel
Save