From c48d9f22302dee82c20734f36a42adbd805cf556 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Fri, 1 Oct 2021 20:39:52 +0530 Subject: [PATCH] refactor: Use identifier instead of name feat: Create EditorIdentifier enum --- .../panes/general-segments/Defaults.tsx | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/preferences/panes/general-segments/Defaults.tsx b/app/assets/javascripts/preferences/panes/general-segments/Defaults.tsx index 5ebb8725f..e6e8f6127 100644 --- a/app/assets/javascripts/preferences/panes/general-segments/Defaults.tsx +++ b/app/assets/javascripts/preferences/panes/general-segments/Defaults.tsx @@ -20,23 +20,39 @@ type Props = { application: WebApplication; }; -const getEditorIconType = (name: string): IconType | null => { - switch (name) { - case 'Bold Editor': - case 'Plus Editor': +enum EditorIdentifier { + PlainEditor = 'plain-editor', + BoldEditor = 'org.standardnotes.bold-editor', + CodeEditor = 'org.standardnotes.code-editor', + MarkdownBasic = 'org.standardnotes.simple-markdown-editor', + MarkdownMath = 'org.standardnotes.fancy-markdown-editor', + MarkdownMinimist = 'org.standardnotes.minimal-markdown-editor', + MarkdownPro = 'org.standardnotes.advanced-markdown-editor', + PlusEditor = 'org.standardnotes.plus-editor', + SecureSpreadsheets = 'org.standardnotes.standard-sheets', + TaskEditor = 'org.standardnotes.simple-task-editor', + TokenVault = 'org.standardnotes.token-vault', +} + +const getEditorIconType = (identifier: string): IconType | null => { + switch (identifier) { + case EditorIdentifier.BoldEditor: + case EditorIdentifier.PlusEditor: return 'rich-text'; - case 'TokenVault': + case EditorIdentifier.MarkdownBasic: + case EditorIdentifier.MarkdownMath: + case EditorIdentifier.MarkdownMinimist: + case EditorIdentifier.MarkdownPro: + return 'markdown'; + case EditorIdentifier.TokenVault: return 'authenticator'; - case 'Secure Spreadsheets': + case EditorIdentifier.SecureSpreadsheets: return 'spreadsheets'; - case 'Task Editor': + case EditorIdentifier.TaskEditor: return 'tasks'; - case 'Code Editor': + case EditorIdentifier.CodeEditor: return 'code'; } - if (name.includes('Markdown')) { - return 'markdown'; - } return null; }; @@ -87,11 +103,12 @@ export const Defaults: FunctionComponent = ({ application }) => { return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; }) .map((editor) => { - const iconType = getEditorIconType(editor.name); + const identifier = editor.package_info.identifier; + const iconType = getEditorIconType(identifier); return { label: editor.name, - value: editor.package_info.identifier, + value: identifier, ...(iconType ? { icon: iconType } : null), }; });