diff --git a/app/categories/table.tsx b/app/categories/table.tsx index 58118d7..ea8a883 100644 --- a/app/categories/table.tsx +++ b/app/categories/table.tsx @@ -8,14 +8,18 @@ import { TableRow, TableCell, Tooltip, + Select, + SelectItem, + Selection, } from '@nextui-org/react' import { DeleteIcon, EditIcon } from '@/components/icons' -import { BookmarkCategoryWithBookmarks } from '@/types' +import { BookmarkCategory, BookmarkCategoryWithBookmarks } from '@/types' import { useRouter } from 'next/navigation' const columns = [ { name: 'NAME', uid: 'name' }, + { name: 'POSITION', uid: 'position' }, { name: 'BOOKMARK COUNT', uid: 'bookmarkcount' }, { name: 'ACTIONS', uid: 'actions' }, ] @@ -41,6 +45,26 @@ export default function TableComponent({ return } + const updateCategory = async ( + bookmark_category: BookmarkCategory, + position: Selection + ) => { + if (position === 'all') return + + const body = { + ...bookmark_category, + position: parseInt(position.values().next().value), + } + + await fetch('/api/bookmark_category', { + method: 'PATCH', + body: JSON.stringify(body), + }) + + router.refresh() + return + } + return ( <> @@ -52,32 +76,51 @@ export default function TableComponent({ )} - {(item) => ( - - {item.name} - {item.bookmark.length} - -
- - - - - - - - deleteCategory(item.id) - }> - - - -
-
-
- )} + {(item) => { + const { bookmark: _, ...category } = item + return ( + + {item.name} + + + + {item.bookmark.length} + +
+ + + + + + + + deleteCategory(item.id) + }> + + + +
+
+
+ ) + }}
diff --git a/types/index.ts b/types/index.ts index 72671b6..13a081a 100644 --- a/types/index.ts +++ b/types/index.ts @@ -26,6 +26,7 @@ export type Bookmark = z.infer const bookmarkCategory = { name: z.string().nonempty(), + position: z.number(), } export const newBookmarkCategorySchema = z.object({ @@ -42,6 +43,7 @@ export type BookmarkCategory = z.infer export const bookmarkCategoryWithBookmarksSchema = z.object({ id: z.number(), + userId: z.number(), ...bookmarkCategory, bookmark: bookmarkSchema.array(), })