mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-26 01:34:38 +10:00
feat: slight optimisation with removing from collection
This commit is contained in:
@@ -115,13 +115,22 @@ const inCollections = computed(() =>
|
|||||||
async function toggleLibrary() {
|
async function toggleLibrary() {
|
||||||
isLibraryLoading.value = true;
|
isLibraryLoading.value = true;
|
||||||
try {
|
try {
|
||||||
|
const method = inLibrary.value ? "DELETE" : "POST";
|
||||||
await $dropFetch("/api/v1/collection/default/entry", {
|
await $dropFetch("/api/v1/collection/default/entry", {
|
||||||
method: inLibrary.value ? "DELETE" : "POST",
|
method,
|
||||||
body: {
|
body: {
|
||||||
id: props.gameId,
|
id: props.gameId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await refreshLibrary();
|
if (method == "DELETE") {
|
||||||
|
// In place remove
|
||||||
|
library.value.entries.splice(
|
||||||
|
library.value.entries.findIndex((e) => e.gameId == props.gameId),
|
||||||
|
1
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await refreshLibrary();
|
||||||
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
createModal(
|
createModal(
|
||||||
ModalType.Notification,
|
ModalType.Notification,
|
||||||
@@ -138,18 +147,26 @@ async function toggleLibrary() {
|
|||||||
|
|
||||||
async function toggleCollection(id: string) {
|
async function toggleCollection(id: string) {
|
||||||
try {
|
try {
|
||||||
const collection = collections.value.find((e) => e.id == id);
|
const collectionIndex = collections.value.findIndex((e) => e.id == id);
|
||||||
if (!collection) return;
|
if (collectionIndex == -1) return;
|
||||||
const index = collection.entries.findIndex((e) => e.gameId == props.gameId);
|
const index = collections.value[collectionIndex].entries.findIndex(
|
||||||
|
(e) => e.gameId == props.gameId
|
||||||
|
);
|
||||||
|
|
||||||
|
const method = index == -1 ? "POST" : "DELETE";
|
||||||
await $dropFetch(`/api/v1/collection/${id}/entry`, {
|
await $dropFetch(`/api/v1/collection/${id}/entry`, {
|
||||||
method: index == -1 ? "POST" : "DELETE",
|
method,
|
||||||
body: {
|
body: {
|
||||||
id: props.gameId,
|
id: props.gameId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await refreshCollection(id);
|
if (method == "DELETE") {
|
||||||
|
collections.value[collectionIndex].entries.splice(index, 1);
|
||||||
|
} else {
|
||||||
|
// We HAVE to refresh because we need to pull game data
|
||||||
|
await refreshCollection(id);
|
||||||
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
createModal(
|
createModal(
|
||||||
ModalType.Notification,
|
ModalType.Notification,
|
||||||
@@ -159,7 +176,6 @@ async function toggleCollection(id: string) {
|
|||||||
},
|
},
|
||||||
(_, c) => c()
|
(_, c) => c()
|
||||||
);
|
);
|
||||||
} finally {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user