|
|
|
@ -8,30 +8,37 @@ import {
|
|
|
|
ModalFooter,
|
|
|
|
ModalFooter,
|
|
|
|
useDisclosure,
|
|
|
|
useDisclosure,
|
|
|
|
} from '@nextui-org/modal'
|
|
|
|
} from '@nextui-org/modal'
|
|
|
|
import {
|
|
|
|
import { Select, SelectSection, SelectItem } from '@nextui-org/select'
|
|
|
|
Dropdown,
|
|
|
|
import { Selection } from '@nextui-org/react'
|
|
|
|
DropdownTrigger,
|
|
|
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
|
|
|
DropdownItem,
|
|
|
|
|
|
|
|
} from '@nextui-org/dropdown'
|
|
|
|
|
|
|
|
import { Button } from '@nextui-org/button'
|
|
|
|
import { Button } from '@nextui-org/button'
|
|
|
|
import { Input } from '@nextui-org/input'
|
|
|
|
import { Input } from '@nextui-org/input'
|
|
|
|
import { Icon } from '@iconify/react'
|
|
|
|
import { Icon } from '@iconify/react'
|
|
|
|
import { ChevronDownIcon } from './ChevronDownIcon'
|
|
|
|
|
|
|
|
import { useRouter } from 'next/navigation'
|
|
|
|
import { useRouter } from 'next/navigation'
|
|
|
|
import { useState } from 'react'
|
|
|
|
import { useState } from 'react'
|
|
|
|
|
|
|
|
import { Tab, Tabs } from '@nextui-org/tabs'
|
|
|
|
|
|
|
|
import { BookmarkCategory } from '@/types'
|
|
|
|
|
|
|
|
|
|
|
|
export default function NewBookmarkForm() {
|
|
|
|
export default function NewBookmarkForm({
|
|
|
|
|
|
|
|
categories,
|
|
|
|
|
|
|
|
}: {
|
|
|
|
|
|
|
|
categories: BookmarkCategory[]
|
|
|
|
|
|
|
|
}) {
|
|
|
|
const { isOpen, onOpen, onOpenChange } = useDisclosure()
|
|
|
|
const { isOpen, onOpen, onOpenChange } = useDisclosure()
|
|
|
|
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
const router = useRouter()
|
|
|
|
const onSubmit = async () => {
|
|
|
|
const onSubmit = () => {
|
|
|
|
|
|
|
|
if (selected === 'bookmark') submitBookmark()
|
|
|
|
|
|
|
|
else if (selected === 'bookmark_category') submitCategory()
|
|
|
|
|
|
|
|
else return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const submitBookmark = async () => {
|
|
|
|
const body = {
|
|
|
|
const body = {
|
|
|
|
name,
|
|
|
|
name,
|
|
|
|
link,
|
|
|
|
link,
|
|
|
|
description,
|
|
|
|
description,
|
|
|
|
url,
|
|
|
|
url,
|
|
|
|
category_id: selectedKey === 'Other' ? 2 : 1,
|
|
|
|
category_id: parseInt(value.currentKey),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await fetch('/api/bookmark', {
|
|
|
|
await fetch('/api/bookmark', {
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
@ -41,12 +48,28 @@ export default function NewBookmarkForm() {
|
|
|
|
router.refresh()
|
|
|
|
router.refresh()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const submitCategory = async () => {
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
|
|
|
|
name: categoryName,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await fetch('/api/bookmark_category', {
|
|
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
onOpenChange()
|
|
|
|
|
|
|
|
router.refresh()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [selected, setSelected] = useState('bookmark')
|
|
|
|
|
|
|
|
|
|
|
|
const [name, setName] = useState('')
|
|
|
|
const [name, setName] = useState('')
|
|
|
|
const [link, setLink] = useState('')
|
|
|
|
const [link, setLink] = useState('')
|
|
|
|
const [description, setDescription] = useState('')
|
|
|
|
const [description, setDescription] = useState('')
|
|
|
|
const [url, setUrl] = useState('')
|
|
|
|
const [url, setUrl] = useState('')
|
|
|
|
|
|
|
|
|
|
|
|
const [selectedKey, setSelectedKey] = useState('Other')
|
|
|
|
const [categoryName, setCategoryName] = useState('')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [value, setValue] = useState<Selection>(new Set([]))
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
@ -67,84 +90,95 @@ export default function NewBookmarkForm() {
|
|
|
|
onOpenChange={onOpenChange}
|
|
|
|
onOpenChange={onOpenChange}
|
|
|
|
placement='center'
|
|
|
|
placement='center'
|
|
|
|
hideCloseButton>
|
|
|
|
hideCloseButton>
|
|
|
|
<ModalContent
|
|
|
|
<ModalContent>
|
|
|
|
onKeyUp={(e) => {
|
|
|
|
|
|
|
|
if (e.key === 'Enter') onSubmit()
|
|
|
|
|
|
|
|
}}>
|
|
|
|
|
|
|
|
{(onClose) => (
|
|
|
|
{(onClose) => (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<ModalHeader className='flex gap-2'>
|
|
|
|
<ModalHeader className='flex gap-2'>
|
|
|
|
New Bookmark
|
|
|
|
New Bookmark/Category
|
|
|
|
<Icon
|
|
|
|
<Icon
|
|
|
|
icon='mdi:bookmark-box'
|
|
|
|
icon='mdi:bookmark-box'
|
|
|
|
fontSize={30}
|
|
|
|
fontSize={30}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</ModalHeader>
|
|
|
|
</ModalHeader>
|
|
|
|
<ModalBody className='gap-4'>
|
|
|
|
<ModalBody className='gap-4'>
|
|
|
|
<Dropdown>
|
|
|
|
<Tabs
|
|
|
|
<DropdownTrigger className='flex justify-start'>
|
|
|
|
selectedKey={selected}
|
|
|
|
<Button
|
|
|
|
onSelectionChange={(key) =>
|
|
|
|
startContent={
|
|
|
|
setSelected(key.toString())
|
|
|
|
<span className='text-default-400'>
|
|
|
|
}
|
|
|
|
Category:
|
|
|
|
fullWidth
|
|
|
|
</span>
|
|
|
|
color='primary'>
|
|
|
|
}
|
|
|
|
<Tab
|
|
|
|
endContent={
|
|
|
|
key='bookmark'
|
|
|
|
<ChevronDownIcon className='text-small' />
|
|
|
|
title={'Bookmark'}>
|
|
|
|
}
|
|
|
|
<form className='flex flex-col gap-4'>
|
|
|
|
variant='flat'>
|
|
|
|
<Select
|
|
|
|
<div className='w-full text-start'>
|
|
|
|
label='Select category'
|
|
|
|
{selectedKey}
|
|
|
|
placeholder='Select a category'
|
|
|
|
</div>
|
|
|
|
selectedKeys={value}
|
|
|
|
</Button>
|
|
|
|
onSelectionChange={setValue}>
|
|
|
|
</DropdownTrigger>
|
|
|
|
{categories.length > 0 ? (
|
|
|
|
<DropdownMenu
|
|
|
|
categories.map(
|
|
|
|
disallowEmptySelection
|
|
|
|
(category) => (
|
|
|
|
selectionMode='single'
|
|
|
|
<SelectItem
|
|
|
|
selectedKeys={selectedKey}
|
|
|
|
key={
|
|
|
|
disabledKeys={['disabled']}>
|
|
|
|
category.id
|
|
|
|
<DropdownItem
|
|
|
|
}
|
|
|
|
key='disabled'
|
|
|
|
value={
|
|
|
|
className='capitalize'>
|
|
|
|
category.id
|
|
|
|
Select Category
|
|
|
|
}>
|
|
|
|
</DropdownItem>
|
|
|
|
{category.name}
|
|
|
|
<DropdownItem
|
|
|
|
</SelectItem>
|
|
|
|
key='Coding'
|
|
|
|
)
|
|
|
|
onClick={() => {
|
|
|
|
)
|
|
|
|
setSelectedKey('Coding')
|
|
|
|
) : (
|
|
|
|
}}
|
|
|
|
<SelectItem
|
|
|
|
className='capitalize'>
|
|
|
|
key={'test'}
|
|
|
|
Coding
|
|
|
|
value={'test'}>
|
|
|
|
</DropdownItem>
|
|
|
|
{'test'}
|
|
|
|
<DropdownItem
|
|
|
|
</SelectItem>
|
|
|
|
key='Other'
|
|
|
|
)}
|
|
|
|
onClick={() => {
|
|
|
|
</Select>
|
|
|
|
setSelectedKey('Other')
|
|
|
|
<Input
|
|
|
|
}}
|
|
|
|
autoFocus
|
|
|
|
className='capitalize'>
|
|
|
|
label='Name'
|
|
|
|
Other
|
|
|
|
placeholder='Enter Name'
|
|
|
|
</DropdownItem>
|
|
|
|
variant='bordered'
|
|
|
|
</DropdownMenu>
|
|
|
|
value={name}
|
|
|
|
</Dropdown>
|
|
|
|
onChange={(event) => {
|
|
|
|
<Input
|
|
|
|
setName(event.target.value)
|
|
|
|
autoFocus
|
|
|
|
}}
|
|
|
|
label='Name'
|
|
|
|
/>
|
|
|
|
placeholder='Enter Name'
|
|
|
|
<Input
|
|
|
|
variant='bordered'
|
|
|
|
label='Url'
|
|
|
|
value={name}
|
|
|
|
placeholder='Enter Url'
|
|
|
|
onChange={(event) => {
|
|
|
|
variant='bordered'
|
|
|
|
setName(event.target.value)
|
|
|
|
value={url}
|
|
|
|
}}
|
|
|
|
onChange={(event) => {
|
|
|
|
/>
|
|
|
|
setUrl(event.target.value)
|
|
|
|
<Input
|
|
|
|
}}
|
|
|
|
label='Url'
|
|
|
|
/>
|
|
|
|
placeholder='Enter Url'
|
|
|
|
</form>
|
|
|
|
variant='bordered'
|
|
|
|
</Tab>
|
|
|
|
value={url}
|
|
|
|
<Tab
|
|
|
|
onChange={(event) => {
|
|
|
|
key='bookmark_category'
|
|
|
|
setUrl(event.target.value)
|
|
|
|
title={'Bookmark Category'}>
|
|
|
|
}}
|
|
|
|
<form className='flex flex-col gap-4'>
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
|
|
|
|
autoFocus
|
|
|
|
|
|
|
|
label='Category Name'
|
|
|
|
|
|
|
|
placeholder='Enter Category Name'
|
|
|
|
|
|
|
|
variant='bordered'
|
|
|
|
|
|
|
|
value={categoryName}
|
|
|
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
|
|
|
setCategoryName(
|
|
|
|
|
|
|
|
event.target.value
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
</Tab>
|
|
|
|
|
|
|
|
</Tabs>
|
|
|
|
</ModalBody>
|
|
|
|
</ModalBody>
|
|
|
|
<ModalFooter>
|
|
|
|
<ModalFooter>
|
|
|
|
<Button
|
|
|
|
<Button
|
|
|
|
|