Skip to content

Commit

Permalink
Cancel delete confirmation if clicking off element
Browse files Browse the repository at this point in the history
  • Loading branch information
bmitchinson committed Mar 25, 2024
1 parent 8569566 commit 4f475ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@capacitor/cli": "^5.0.5",
"@capacitor/core": "^5.0.5",
"@capacitor/ios": "^5.0.5",
"@svelte-put/clickoutside": "^3.0.1",
"date-fns": "^3.3.1",
"firebase": "^10.1.0",
"svelecte": "^3.17.2"
Expand Down
7 changes: 7 additions & 0 deletions src/components/purchases/PastPurchase.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { format } from "date-fns";
import { Database } from "../../lib/Database";
import { clickoutside } from "@svelte-put/clickoutside";
import type {
Purchase,
WithFirebaseDocumentRef,
Expand All @@ -20,6 +21,10 @@
deleteConfirmationActive =
$purchaseAskingToConfirmDelete?.id === purchase.ref.id;
}
const cancelDeleteConfirmation = () => {
deleteConfirmationActive && purchaseAskingToConfirmDelete.set(undefined);
};
</script>

<tr data-testid="purchase-list-item-{index}">
Expand Down Expand Up @@ -47,6 +52,8 @@
class="text-center button-cell"
data-testid="delete-item-{index}"
class:under-edit={isUnderEdit}
use:clickoutside
on:clickoutside={cancelDeleteConfirmation}
><button
on:click={() => {
if (deleteConfirmationActive) {
Expand Down
11 changes: 9 additions & 2 deletions tests/main-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ test.describe("Deleting", () => {
await clickDeletePurchaseAtIndex(page, 0);
await expect(await purchasesOnPage(page)).toBe(3);
});
test("Clicking elsewhere after one delete click removes the confirmation prompt", async ({
page,
}) => {
await clickDeletePurchaseAtIndex(page, 0);
await page.getByTestId("money-icon").click();

await expect(page.getByTestId("delete-item-0")).toContainText("🗑️");
await expect(page.getByTestId("delete-item-0")).not.toHaveText("✅");
});
test("Deleting clears any purchase from being under edit", async ({
page,
}) => {
Expand Down Expand Up @@ -268,8 +277,6 @@ test.describe("Reset", () => {

// todo: firebase rules to require login?

// todo: Clicking anywhere else on the page clears the purchase delete confirmation

// idea: sort toggle (sort purchases by entry date or purchase date)

// idea: dark theme

0 comments on commit 4f475ce

Please sign in to comment.