Finished bulk delete links

This commit is contained in:
Isaac Wise
2024-02-10 00:37:48 -06:00
parent 193c66123b
commit ea31eb47ae
12 changed files with 195 additions and 20 deletions
+22
View File
@@ -24,6 +24,7 @@ type LinkStore = {
link: LinkIncludingShortenedCollectionAndTags
) => Promise<ResponseObject>;
removeLink: (linkId: number) => Promise<ResponseObject>;
deleteLinksById: (linkIds: number[]) => Promise<ResponseObject>;
resetLinks: () => void;
};
@@ -146,6 +147,27 @@ const useLinkStore = create<LinkStore>()((set) => ({
return { ok: response.ok, data: data.response };
},
deleteLinksById: async (linkIds: number[]) => {
const response = await fetch("/api/v1/links/bulk", {
body: JSON.stringify({ linkIds }),
headers: {
"Content-Type": "application/json",
},
method: "DELETE",
});
const data = await response.json();
if (response.ok) {
set((state) => ({
links: state.links.filter((e) => !linkIds.includes(e.id)),
}));
useTagStore.getState().setTags();
useCollectionStore.getState().setCollections();
}
return { ok: response.ok, data: data.response };
},
resetLinks: () => set({ links: [] }),
}));