blob: 54cf913752725e67eb647db14f7353016abcd5a5 (
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
|
"use client";
import APIClient from "@/lib/api";
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) {
alert(error.message);
return;
}
router.refresh();
};
return (
<div className="p-4">
<input
type="text"
placeholder="Link"
value={link}
onChange={(val) => setLink(val.target.value)}
onKeyUp={async (event) => {
if (event.key == "Enter") {
bookmarkLink();
setLink("");
}
}}
className="w-10/12 px-4 py-2 border rounded-md focus:outline-none focus:border-blue-300"
/>
<button className="w-2/12 px-1 py-2" onClick={bookmarkLink}>
Submit
</button>
</div>
);
}
|