diff options
| author | MohamedBassem <me@mbassem.com> | 2024-02-08 02:16:51 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-02-08 02:23:29 +0000 |
| commit | 2659da517aeec0fe955422dee76f7de292f1a591 (patch) | |
| tree | 5150d69d2e5b70aea2cad6adefc6e2511d0d29da /web/app/dashboard/bookmarks/components/AddLink.tsx | |
| parent | 7344f167edae95b2edd984ec1ae0ef5359d1e028 (diff) | |
| download | karakeep-2659da517aeec0fe955422dee76f7de292f1a591.tar.zst | |
[feature] Introduce a sidebar
Diffstat (limited to 'web/app/dashboard/bookmarks/components/AddLink.tsx')
| -rw-r--r-- | web/app/dashboard/bookmarks/components/AddLink.tsx | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/web/app/dashboard/bookmarks/components/AddLink.tsx b/web/app/dashboard/bookmarks/components/AddLink.tsx new file mode 100644 index 00000000..fab4db8b --- /dev/null +++ b/web/app/dashboard/bookmarks/components/AddLink.tsx @@ -0,0 +1,43 @@ +"use client"; + +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import APIClient from "@/lib/api"; +import { Plus } from "lucide-react"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; + +export default function AddLink() { + const router = useRouter(); + const [link, setLink] = useState(""); + + const bookmarkLink = async () => { + const [_resp, error] = await APIClient.bookmarkLink(link); + if (error) { + // TODO: Proper error handling + alert(error.message); + return; + } + router.refresh(); + }; + + return ( + <div className="py-4 container flex w-full items-center space-x-2"> + <Input + type="text" + placeholder="Link" + value={link} + onChange={(val) => setLink(val.target.value)} + onKeyUp={async (event) => { + if (event.key == "Enter") { + bookmarkLink(); + setLink(""); + } + }} + /> + <Button onClick={bookmarkLink}> + <Plus /> + </Button> + </div> + ); +} |
