From 80a98887d5a9383e07093067b972358d1381c086 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Wed, 16 Aug 2023 21:25:07 +0800 Subject: [PATCH] New feature: category change in editBookmarkForm --- components/editBookmarkForm.tsx | 52 +++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/components/editBookmarkForm.tsx b/components/editBookmarkForm.tsx index 6f2d49d..d497c9c 100644 --- a/components/editBookmarkForm.tsx +++ b/components/editBookmarkForm.tsx @@ -7,13 +7,19 @@ import { ModalBody, ModalFooter, } from '@nextui-org/modal' +import { + Dropdown, + DropdownItem, + DropdownMenu, + DropdownTrigger, +} from '@nextui-org/dropdown' import { Button } from '@nextui-org/button' import { Input } from '@nextui-org/input' import { Icon } from '@iconify/react' import { useRouter } from 'next/navigation' import { useContext, useState } from 'react' -import { Bookmark } from '@/types' import { BookmarkContext, EditBookmarkContext } from '@/app/providers' +import { ChevronDownIcon } from './ChevronDownIcon' export default function EditBookmarkForm() { const { isEditBookmark, onIsEditBookmarkChange } = @@ -22,7 +28,10 @@ export default function EditBookmarkForm() { const router = useRouter() const onSubmit = async () => { - const body = bookmark + const body = { + ...bookmark, + category_id: selectedKey === 'Other' ? 2 : 1, + } await fetch('/api/bookmark', { method: 'PATCH', @@ -32,6 +41,10 @@ export default function EditBookmarkForm() { router.refresh() } + const [selectedKey, setSelectedKey] = useState( + bookmark.category_id == 2 ? 'Other' : 'Coding' + ) + return ( <> { - console.log(e.key) if (e.key === 'Enter') onSubmit() }}> {(onClose) => ( @@ -91,6 +103,40 @@ export default function EditBookmarkForm() { }) }} /> + + + + + + { + setSelectedKey('Coding') + }} + className='capitalize'> + Coding + + { + setSelectedKey('Other') + }} + className='capitalize'> + Other + + +