refactor(client-side): make list actions async
This commit is contained in:
parent
a7b8c07952
commit
609562b7fa
@ -4,14 +4,14 @@ import { useRoute, useRouter } from "#app";
|
|||||||
|
|
||||||
const base = `/user/me`;
|
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?.splice(
|
||||||
values!.findIndex((a) => a._id == id),
|
values!.findIndex((a) => a._id == id),
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
const key = type === "story" ? "stories" : "authors";
|
const key = type === "story" ? "stories" : "authors";
|
||||||
const todo = [id];
|
const todo = [id];
|
||||||
useApiFetch(`${base}/favs`, {
|
await useApiFetch(`${base}/favs`, {
|
||||||
method: "put",
|
method: "put",
|
||||||
body: {
|
body: {
|
||||||
[key]: {
|
[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)[],
|
values: ((any & { _id: number }) | number)[],
|
||||||
id: number,
|
id: number,
|
||||||
action: "hide" | "subscribe" | "unsubscribe",
|
action: "hide" | "subscribe" | "unsubscribe",
|
||||||
@ -36,7 +36,7 @@ export const subscriptions = (
|
|||||||
values!.findIndex((a) => a._id == id || a == id),
|
values!.findIndex((a) => a._id == id || a == id),
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
useApiFetch(`${base}/${action}`, {
|
await useApiFetch(`${base}/${action}`, {
|
||||||
body: {
|
body: {
|
||||||
push: {
|
push: {
|
||||||
[type]: [id],
|
[type]: [id],
|
||||||
@ -46,7 +46,7 @@ export const subscriptions = (
|
|||||||
method: "put",
|
method: "put",
|
||||||
});
|
});
|
||||||
} else if (action == "subscribe") {
|
} else if (action == "subscribe") {
|
||||||
useApiFetch(`${base}/subscriptions`, {
|
await useApiFetch(`${base}/subscriptions`, {
|
||||||
body: {
|
body: {
|
||||||
push: {
|
push: {
|
||||||
[type]: [id],
|
[type]: [id],
|
||||||
@ -56,7 +56,7 @@ export const subscriptions = (
|
|||||||
method: "put",
|
method: "put",
|
||||||
});
|
});
|
||||||
} else if (action == "unsubscribe") {
|
} else if (action == "unsubscribe") {
|
||||||
useApiFetch(`${base}/subscriptions`, {
|
await useApiFetch(`${base}/subscriptions`, {
|
||||||
body: {
|
body: {
|
||||||
pull: {
|
pull: {
|
||||||
[type]: [id],
|
[type]: [id],
|
||||||
|
Loading…
Reference in New Issue
Block a user