From d4e9865ada24596aafd18fe84562f435557748b5 Mon Sep 17 00:00:00 2001 From: ChaotiCryptidz Date: Wed, 19 Jan 2022 13:54:13 +0000 Subject: [PATCH] add settings page --- package.json | 2 - src/pages.tsx | 2 + src/settings/Settings.ts | 20 ++++ src/translations/en.js | 26 ++++- src/ui/pages/Me.tsx | 28 +---- .../pages/Secrets/KeyValue/KeyValueEdit.tsx | 45 ++++---- .../pages/Secrets/KeyValue/KeyValueList.tsx | 7 +- src/ui/pages/Secrets/KeyValue/KeyValueNew.tsx | 2 +- src/ui/pages/Secrets/TOTP/TOTPList.tsx | 38 ++++--- src/ui/pages/SetLanguage.tsx | 8 +- src/ui/pages/Settings/GeneralSettings.tsx | 105 ++++++++++++++++++ .../pages/Settings/KeyValueEditorSettings.tsx | 51 +++++++++ src/ui/pages/Settings/Settings.tsx | 22 ++++ 13 files changed, 273 insertions(+), 83 deletions(-) create mode 100644 src/ui/pages/Settings/GeneralSettings.tsx create mode 100644 src/ui/pages/Settings/KeyValueEditorSettings.tsx create mode 100644 src/ui/pages/Settings/Settings.tsx diff --git a/package.json b/package.json index 19586cb..d16df9d 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "@babel/plugin-transform-runtime": "^7.16.8", "@babel/preset-env": "^7.16.8", "@types/file-saver": "^2.0.5", - "@types/hjson": "^2.4.3", "@types/js-yaml": "^4.0.5", "@types/prismjs": "^1.16.6", "@types/uikit": "^3.3.2", @@ -41,7 +40,6 @@ "core-js": "^3.20.3", "date-fns": "^2.28.0", "file-saver": "^2.0.5", - "hjson": "^3.2.2", "i18next": "^21.6.6", "js-yaml": "^4.1.0", "json5": "^2.2.0", diff --git a/src/pages.tsx b/src/pages.tsx index 6738d58..f279cce 100644 --- a/src/pages.tsx +++ b/src/pages.tsx @@ -29,6 +29,7 @@ import { PolicyView } from "./ui/pages/Policies/PolicyView"; import { Secrets } from "./ui/pages/Secrets/SecretsHome"; import { SetLanguage } from "./ui/pages/SetLanguage"; import { SetVaultURL } from "./ui/pages/SetVaultURL"; +import { Settings } from "./ui/pages/Settings/Settings"; import { TOTPDelete } from "./ui/pages/Secrets/TOTP/TOTPDelete"; import { TOTPList } from "./ui/pages/Secrets/TOTP/TOTPList"; import { TOTPNew } from "./ui/pages/Secrets/TOTP/TOTPNew"; @@ -59,6 +60,7 @@ export const Main = () => ( + diff --git a/src/settings/Settings.ts b/src/settings/Settings.ts index 37f3e09..138ad21 100644 --- a/src/settings/Settings.ts +++ b/src/settings/Settings.ts @@ -64,4 +64,24 @@ export class Settings { this.storage.setItem("theme", value); this.alertChange("theme"); } + + get kvEditorDefaultLanguage(): string { + return this.storage.getItem("kvEditorDefaultLanguage") || "yaml"; + } + + set kvEditorDefaultLanguage(value: string) { + this.storage.setItem("kvEditorDefaultLanguage", value); + this.alertChange("kvEditorDefaultLanguage"); + } + + get kvEditorIndent(): number { + const value = this.storage.getItem("kvEditorIndent"); + if (value) return parseInt(value); + return 2; + } + + set kvEditorIndent(value: number) { + this.storage.setItem("kvEditorIndent", String(value)); + this.alertChange("kvEditorIndent"); + } } diff --git a/src/translations/en.js b/src/translations/en.js index e4aafbc..4a139db 100644 --- a/src/translations/en.js +++ b/src/translations/en.js @@ -35,9 +35,9 @@ module.exports = { not_implemented: "Not Yet Implemented", // Copyable Modal - copy_box_download_btn: "Download", - copy_box_copy_btn: "Copy", - copy_box_close_btn: "Close", + copy_modal_download_btn: "Download", + copy_modal_copy_btn: "Copy", + copy_modal_close_btn: "Close", // Generic Loading Text content_loading: "Loading..", @@ -54,8 +54,7 @@ module.exports = { me_seal_vault_btn: "Seal Vault", me_copy_token_btn: "Copy Token", me_renew_lease_btn: "Renew Token Lease", - me_change_language_btn: "Change Language", - me_set_vault_url_btn: "Set Vault URL", + me_settings_btn: "Settings", // Home Page home_page_title: "Home", @@ -69,6 +68,23 @@ module.exports = { home_policies_title: "Policies", home_policies_description: "Manage policies and permissions.", + // Settings Page + settings_title: "Settings", + + // General Settings + settings_general_title: "General", + settings_general_theme: "Theme", + settings_general_vault_url: "Vault API URL", + settings_general_language: "Language", + settings_general_page_direction: "Page Direction", + settings_general_page_direction_ltr: "Left to Right", + settings_general_page_direction_rtl: "Right to Left", + + // Key/Value Editor Settings + settings_kveditor_title: "Key/Value Editor", + settings_kveditor_default_language: "Default Data Interchange Format", + settings_kveditor_default_indent: "Default Indent", + // Set Vault URL Page set_vault_url_title: "Set Vault URL", set_vault_url_placeholder: "Vault URL", diff --git a/src/ui/pages/Me.tsx b/src/ui/pages/Me.tsx index 28ffa94..8e125e3 100644 --- a/src/ui/pages/Me.tsx +++ b/src/ui/pages/Me.tsx @@ -1,6 +1,6 @@ +import { Button } from "../elements/Button"; import { Component, JSX, createRef } from "preact"; import { DefaultPageProps } from "../../types/DefaultPageProps"; -import { InputWithTitle } from "../elements/InputWithTitle"; import { PageTitle } from "../elements/PageTitle"; import { addClipboardNotifications, setErrorText } from "../../pageUtils"; import { route } from "preact-router"; @@ -103,30 +103,10 @@ export class Me extends Component { )} -
  • - {i18next.t("me_change_language_btn")} -
  • -
  • - {i18next.t("me_set_vault_url_btn")} -
  • - - - +
    + +