blob: c66cc0ad30427ff871d7e41491c7afd4d29b9fda (
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
|
import { useEffect, useState } from "react";
import { Settings } from "./settings";
export default function SavePage({ settings }: { settings: Settings }) {
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | undefined>(undefined);
async function runFetch() {
const resp = await fetch(
`${settings.address}/api/trpc/bookmarks.bookmarkLink`,
{
method: "POST",
},
);
if (!resp.ok) {
setError("Something went wrong: " + (await resp.json()));
}
setLoading(false);
}
useEffect(() => {
runFetch();
}, []);
if (loading) {
return <div>Loading ...</div>;
}
if (error) {
return <div className="text-red-500">{error} ...</div>;
}
return (
<div>
SAVED!
<button onClick={runFetch}> Reload </button>
</div>
);
}
|