From 0a2127b626a77b3a3495a5e52d6cf86bcab52494 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Sat, 17 Apr 2021 11:06:34 +0100 Subject: [PATCH] Move most of currentTitleSecretText's functionality into page.titlePrefix, using less code. --- src/main.js | 1 - src/pageUtils.js | 7 ++----- src/pages/KeyValue/KeyValueDelete.js | 4 +++- src/pages/KeyValue/KeyValueNew.js | 3 +++ src/pages/KeyValue/KeyValueSecretsEdit.js | 3 +++ src/pages/KeyValue/KeyValueVersions.js | 3 +++ src/pages/TOTP/NewTOTP.js | 5 +++++ src/pages/Transit/TransitDecrypt.js | 4 ++++ src/pages/Transit/TransitEncrypt.js | 4 ++++ src/types/Page.js | 3 +++ 10 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main.js b/src/main.js index 2be167e..a455527 100644 --- a/src/main.js +++ b/src/main.js @@ -9,7 +9,6 @@ import Prism from "prismjs"; import "prismjs/components/prism-json"; Prism.highlightAll(); - import { changePage, renderPage, diff --git a/src/pageUtils.js b/src/pageUtils.js index b02f3c0..00a0967 100644 --- a/src/pageUtils.js +++ b/src/pageUtils.js @@ -42,11 +42,8 @@ export function setPageTitle(title) { function currentTitleSecretText() { let currentSecretText = pageState.currentSecret; - if (pageState.currentPage == pages.KEY_VALUE_SECRETS_EDIT) currentSecretText += " (edit)"; - if (pageState.currentPage == pages.KEY_VALUE_DELETE) currentSecretText += " (delete)"; - if (pageState.currentPage == pages.KEY_VALUE_VERSIONS) currentSecretText += " (versions)"; - if (pageState.currentPage == pages.NEW_TOTP) currentSecretText += " (new)"; - if (pageState.currentPage == pages.TRANSIT_ENCRYPT) currentSecretText += " (encrypt)"; + currentSecretText += pageState.currentPage.titlePrefix; + if (pageState.currentSecretVersion != "0") currentSecretText += ` (v${pageState.currentSecretVersion})`; return currentSecretText; } diff --git a/src/pages/KeyValue/KeyValueDelete.js b/src/pages/KeyValue/KeyValueDelete.js index b9a2387..fe09227 100644 --- a/src/pages/KeyValue/KeyValueDelete.js +++ b/src/pages/KeyValue/KeyValueDelete.js @@ -38,7 +38,9 @@ export class KeyValueDeletePage extends Page { ] })); } - + get titlePrefix() { + return " (delete)"; + } get name() { return "K/V Delete"; } diff --git a/src/pages/KeyValue/KeyValueNew.js b/src/pages/KeyValue/KeyValueNew.js index 7ee6e98..6959b62 100644 --- a/src/pages/KeyValue/KeyValueNew.js +++ b/src/pages/KeyValue/KeyValueNew.js @@ -76,6 +76,9 @@ export class KeyValueNewPage extends Page { }); } + get titlePrefix() { + return " (new)"; + } get name() { return "K/V New"; diff --git a/src/pages/KeyValue/KeyValueSecretsEdit.js b/src/pages/KeyValue/KeyValueSecretsEdit.js index 2e65392..60d0f4e 100644 --- a/src/pages/KeyValue/KeyValueSecretsEdit.js +++ b/src/pages/KeyValue/KeyValueSecretsEdit.js @@ -64,6 +64,9 @@ export class KeyValueSecretsEditPage extends Page { }); } + get titlePrefix() { + return " (edit)"; + } get name() { return "K/V Secrets Edit"; diff --git a/src/pages/KeyValue/KeyValueVersions.js b/src/pages/KeyValue/KeyValueVersions.js index 4a11148..2b51ea6 100644 --- a/src/pages/KeyValue/KeyValueVersions.js +++ b/src/pages/KeyValue/KeyValueVersions.js @@ -39,7 +39,10 @@ export class KeyValueVersionsPage extends Page { }) })); }); + } + get titlePrefix() { + return " (versions)"; } get name() { diff --git a/src/pages/TOTP/NewTOTP.js b/src/pages/TOTP/NewTOTP.js index 48db55c..7b0dcf7 100644 --- a/src/pages/TOTP/NewTOTP.js +++ b/src/pages/TOTP/NewTOTP.js @@ -84,6 +84,11 @@ export class NewTOTPPage extends Page { }); }); } + + get titlePrefix() { + return " (new)"; + } + get name() { return "Create New TOTP"; } diff --git a/src/pages/Transit/TransitDecrypt.js b/src/pages/Transit/TransitDecrypt.js index 60b4ee8..b199f8e 100644 --- a/src/pages/Transit/TransitDecrypt.js +++ b/src/pages/Transit/TransitDecrypt.js @@ -64,6 +64,10 @@ export class TransitDecryptPage extends Page { }); } + get titlePrefix() { + return " (decrypt)"; + } + get name() { return "Transit Decrypt"; } diff --git a/src/pages/Transit/TransitEncrypt.js b/src/pages/Transit/TransitEncrypt.js index f3bdc0b..17c0764 100644 --- a/src/pages/Transit/TransitEncrypt.js +++ b/src/pages/Transit/TransitEncrypt.js @@ -85,6 +85,10 @@ export class TransitEncryptPage extends Page { }); } + get titlePrefix() { + return " (encrypt)"; + } + get name() { return "Transit Encrypt"; } diff --git a/src/types/Page.js b/src/types/Page.js index 07bd5b6..3267557 100644 --- a/src/types/Page.js +++ b/src/types/Page.js @@ -7,6 +7,9 @@ export class Page { get name() { return "Page"; } + get titlePrefix() { + return ""; + } goBack() { changePage(pages.HOME); }