From 609562b7fa23d6e6c3816a0f67eb46b3a641b2bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Tue, 9 Jul 2024 20:33:20 -0400 Subject: [PATCH] refactor(client-side): make list actions async --- lib/client/listActions.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/client/listActions.ts b/lib/client/listActions.ts index 01288ae..463da11 100644 --- a/lib/client/listActions.ts +++ b/lib/client/listActions.ts @@ -4,14 +4,14 @@ import { useRoute, useRouter } from "#app"; const base = `/user/me`; -export const favourites = (values: (any & { _id: number })[], id: number, remove: boolean, type: "story" | "author") => { +export const favourites = async (values: (any & { _id: number })[], id: number, remove: boolean, type: "story" | "author") => { values?.splice( values!.findIndex((a) => a._id == id), 1, ); const key = type === "story" ? "stories" : "authors"; const todo = [id]; - useApiFetch(`${base}/favs`, { + await useApiFetch(`${base}/favs`, { method: "put", body: { [key]: { @@ -22,7 +22,7 @@ export const favourites = (values: (any & { _id: number })[], id: number, remove }); }; -export const subscriptions = ( +export const subscriptions = async ( values: ((any & { _id: number }) | number)[], id: number, action: "hide" | "subscribe" | "unsubscribe", @@ -36,7 +36,7 @@ export const subscriptions = ( values!.findIndex((a) => a._id == id || a == id), 1, ); - useApiFetch(`${base}/${action}`, { + await useApiFetch(`${base}/${action}`, { body: { push: { [type]: [id], @@ -46,7 +46,7 @@ export const subscriptions = ( method: "put", }); } else if (action == "subscribe") { - useApiFetch(`${base}/subscriptions`, { + await useApiFetch(`${base}/subscriptions`, { body: { push: { [type]: [id], @@ -56,7 +56,7 @@ export const subscriptions = ( method: "put", }); } else if (action == "unsubscribe") { - useApiFetch(`${base}/subscriptions`, { + await useApiFetch(`${base}/subscriptions`, { body: { pull: { [type]: [id],