Skip to content

Commit 908f0be

Browse files
committed
delete
1 parent 9084f1d commit 908f0be

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

playground/pages/home.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const Home = () => {
3131
const navigate = useNavigate();
3232
const user = () => params.user || context.user()?.display;
3333

34-
const [repls] = createResource<Repls, string>(user, async (user) => {
34+
const [repls, { mutate }] = createResource<Repls, string>(user, async (user) => {
3535
if (!user) return { total: 0, list: [] };
3636
return await fetch(`${API}/repl/${user}/list`).then((r) => r.json());
3737
});
@@ -101,7 +101,23 @@ export const Home = () => {
101101
<td>{new Date(repl.created_at).toLocaleString()}</td>
102102
<td>
103103
<Icon path={repl.public ? eye : eyeOff} class="w-6 inline m-2 ml-0" />
104-
<Icon path={x} class="w-6 inline m-2 mr-0 text-red-700" />
104+
<Icon
105+
path={x}
106+
class="w-6 inline m-2 mr-0 text-red-700 cursor-pointer"
107+
onClick={async () => {
108+
fetch(`${API}/repl/${repl.id}`, {
109+
method: 'DELETE',
110+
headers: {
111+
authorization: `Bearer ${context.token}`,
112+
},
113+
});
114+
const current = repls.latest!;
115+
mutate({
116+
total: current.total - 1,
117+
list: current.list.filter((x) => x.id !== repl.id),
118+
});
119+
}}
120+
/>
105121
</td>
106122
</tr>
107123
)}

0 commit comments

Comments
 (0)