aboutsummaryrefslogtreecommitdiffstats
path: root/web/app/bookmarks/components/AddLink.tsx
blob: fab4db8bfbad60a7fa7b4c4dd70a6a71d3639c47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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>
  );
}