Skip to content

Commit

Permalink
Green: Delete confirmation working
Browse files Browse the repository at this point in the history
  • Loading branch information
bmitchinson committed Mar 8, 2024
1 parent 0ff7afb commit 4604914
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/components/purchases/PastPurchase.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<script lang="ts">
import { get } from "svelte/store";
import { Database } from "../../lib/Database";
import type {
Purchase,
WithFirebaseDocumentRef,
} from "../../lib/DatabaseTypes";
import { purchaseBeingEdited } from "../../lib/Stores";
import { createEventDispatcher } from "svelte";
import { purchaseAskingToConfirmDelete } from "../../lib/Stores";
export let index: number;
export let purchase: WithFirebaseDocumentRef<Purchase>;
export let isUnderEdit: boolean;
let deleteConfirmationActive = false;
let deleteConfirmationActive: boolean;
$: {
deleteConfirmationActive =
$purchaseAskingToConfirmDelete?.id === purchase.ref.id;
}
</script>

<tr data-testid="purchase-list-item-{index}">
Expand Down Expand Up @@ -40,13 +46,15 @@
on:click={() => {
if (deleteConfirmationActive) {
if (isUnderEdit) purchaseBeingEdited.set(undefined);
Database.get()
.deletePurchase(purchase.ref)
.then(() => {
deleteConfirmationActive = false;
});
purchaseAskingToConfirmDelete.set(undefined);
Database.get().deletePurchase(purchase.ref);
} else {
deleteConfirmationActive = true;
purchaseAskingToConfirmDelete.set(purchase.ref);
console.log(
purchase.ref.id +
" set conf to " +
get(purchaseAskingToConfirmDelete)?.id
);
}
}}>{deleteConfirmationActive ? "confirm" : "delete"}</button
></th
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ import { writable, type Writable } from "svelte/store";
export const purchaseBeingEdited: Writable<
undefined | WithFirebaseDocumentRef<Purchase>
> = writable(undefined);

export const purchaseAskingToConfirmDelete: Writable<
undefined | FirebaseDocumentRef
> = writable(undefined);

0 comments on commit 4604914

Please sign in to comment.