From 5bfaac7c548cee8bd28820947c64e553fddbc5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Tue, 25 Jul 2023 23:10:32 +0200 Subject: [PATCH] Allow to delete an account --- pwa/app.js | 17 +++++++++++++++++ pwa/index.html | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/pwa/app.js b/pwa/app.js index b7aeb0c..b60f77b 100644 --- a/pwa/app.js +++ b/pwa/app.js @@ -50,6 +50,9 @@ class Account { document.addEventListener('DOMContentLoaded', () => { // Functions to open and close a modal function openModal(el) { + if (el.id === 'modal-del-account') { + document.querySelector('#del-account-name').innerHTML = getSelectedAccountName(); + } el.classList.add('is-active'); } @@ -70,6 +73,11 @@ document.addEventListener('DOMContentLoaded', () => { }); } + // Function to get the name of the currently selected account + function getSelectedAccountName() { + return document.querySelector('#account-name').value; + } + // Function to get an account by its name function getAccountByName(name) { const account_string = localStorage.getItem(name); @@ -130,6 +138,15 @@ document.addEventListener('DOMContentLoaded', () => { } }); + // Add a click event on the delete account button to display the confirmation message + document.querySelector('#btn-del-account-confirm').addEventListener('click', (event) => { + const account_name = getSelectedAccountName(); + localStorage.removeItem(account_name); + console.log(`Account ${account_name} deleted.`); + syncAccountList(); + closeAllModals(); + }); + // Add a click event on the new account button to register the new account document.querySelector('#btn-new-account').addEventListener('click', (event) => { console.log('Adding new account…'); diff --git a/pwa/index.html b/pwa/index.html index 118d8ea..787973b 100644 --- a/pwa/index.html +++ b/pwa/index.html @@ -26,6 +26,9 @@

+ Delete +

+

New

@@ -90,5 +93,23 @@ +