Skip to content

Commit 51d5097

Browse files
committed
refactor: use api client for delete follow of assistant
1 parent df0c458 commit 51d5097

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/routes/settings/(nav)/+layout.svelte

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import { debounce } from "$lib/utils/debounce";
1919
2020
import { fly } from "svelte/transition";
21+
import { throwOnError, useAPIClient } from "$lib/APIClient";
2122
2223
interface Props {
2324
data: LayoutData;
@@ -30,6 +31,8 @@
3031
let assistantsSection: HTMLHeadingElement | undefined = $state();
3132
let showContent: boolean = $state(false);
3233
34+
const client = useAPIClient();
35+
3336
function checkDesktopRedirect() {
3437
if (
3538
browser &&
@@ -247,20 +250,23 @@
247250
]}
248251
onclick={(event) => {
249252
event.stopPropagation();
250-
fetch(`${base}/api/assistant/${assistant._id}/subscribe`, {
251-
method: "DELETE",
252-
}).then((r) => {
253-
if (r.ok) {
253+
client
254+
.assistants({
255+
id: assistant._id,
256+
})
257+
.follow.delete()
258+
.then(throwOnError)
259+
.then(() => {
254260
if (assistant._id.toString() === page.params.assistantId) {
255261
goto(`${base}/settings`, { invalidateAll: true });
256262
} else {
257263
invalidateAll();
258264
}
259-
} else {
260-
console.error(r);
261-
$error = r.statusText;
262-
}
263-
});
265+
})
266+
.catch((err) => {
267+
console.error(err);
268+
$error = err.message;
269+
});
264270
}}
265271
>
266272
<CarbonClose class="size-4 text-gray-500" />

0 commit comments

Comments
 (0)