Skip to content

Commit

Permalink
Use promise instead of count
Browse files Browse the repository at this point in the history
  • Loading branch information
tschumpr committed Sep 12, 2024
1 parent 0f10741 commit e0c27a0
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/Geopilot.Frontend/src/pages/admin/deliveryOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,9 @@ export const DeliveryOverview = () => {
}, []);

function handleDelete() {
let completedCount = 0;
for (const row of selectedRows) {
const deletePromises = selectedRows.map(row =>
fetchApi("/api/v1/delivery/" + row, { method: "DELETE" })
.then(() => {
completedCount++;
if (completedCount === selectedRows.length) {
loadDeliveries();
}
})
.then(() => null)
.catch((error: ApiError) => {
if (error.status === 404) {
showAlert(t("deliveryOverviewDeleteIdNotExistError", { id: row }), "error");
Expand All @@ -92,8 +86,12 @@ export const DeliveryOverview = () => {
} else {
showAlert(t("deliveryOverviewDeleteError", { error: error }), "error");
}
});
}
}),
);

Promise.all(deletePromises).then(() => {
loadDeliveries();
});
}

return (
Expand Down

0 comments on commit e0c27a0

Please sign in to comment.