refactor(client-side): make list actions async

This commit is contained in:
parent a7b8c07952
commit 609562b7fa
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

@ -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],