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 +
+ @@ -90,5 +93,23 @@ +Delete account
+ +You are about to delete the following account:
+ +Are you sure?
+