From 88c9b307f0e213fd59e444e0f04362afcb0fb098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Wed, 2 Aug 2023 19:44:40 +0200 Subject: [PATCH] Move account deletion into a dedicated view --- src/accounts.js | 8 ++++++ src/components/NavBarComponent.vue | 1 + src/router/index.js | 18 +++++++++---- src/views/MainView.vue | 20 ++++----------- src/views/ManageAccountsView.vue | 41 ++++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 src/accounts.js create mode 100644 src/views/ManageAccountsView.vue diff --git a/src/accounts.js b/src/accounts.js new file mode 100644 index 0000000..93d0bc3 --- /dev/null +++ b/src/accounts.js @@ -0,0 +1,8 @@ +export function sortAccounts(accounts) { + accounts.value.sort((a, b) => { + const va = `${a.localPart}@${a.domain}`; + const vb = `${b.localPart}@${b.domain}`; + return va.localeCompare(vb); + }); + return accounts; +} diff --git a/src/components/NavBarComponent.vue b/src/components/NavBarComponent.vue index 96776cc..1f479fd 100644 --- a/src/components/NavBarComponent.vue +++ b/src/components/NavBarComponent.vue @@ -23,6 +23,7 @@ const toggleBurger = () => { diff --git a/src/router/index.js b/src/router/index.js index a6b9d4b..6068e97 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -5,8 +5,14 @@ import MainView from '../views/MainView.vue'; import AboutView from '../views/AboutView.vue'; import AddAccountView from '../views/AddAccountView.vue'; import DeleteAccountView from '../views/DeleteAccountView.vue'; +import ManageAccountsView from '../views/ManageAccountsView.vue'; const accounts = useStorage('sake-accounts', []); +const requireAccounts = () => { + if (!accounts.value.length) { + return '/add-account'; + } +}; const router = createRouter({ history: createMemoryHistory(), routes: [ @@ -14,11 +20,7 @@ const router = createRouter({ path: '/', name: 'main', component: MainView, - beforeEnter: (to, from) => { - if (!accounts.value.length) { - return '/add-account'; - } - } + beforeEnter: requireAccounts }, { path: '/about', @@ -35,6 +37,12 @@ const router = createRouter({ name: 'delete-account', component: DeleteAccountView, }, + { + path: '/manage-accounts', + name: 'manage-accounts', + component: ManageAccountsView, + beforeEnter: requireAccounts + }, ] }); diff --git a/src/views/MainView.vue b/src/views/MainView.vue index d35a0a1..256a654 100644 --- a/src/views/MainView.vue +++ b/src/views/MainView.vue @@ -1,4 +1,5 @@ + +