diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/CommentEditor/CommentEditor.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/CommentEditor/CommentEditor.vue index 18bd4344e..baa8fd216 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/CommentEditor/CommentEditor.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/CommentEditor/CommentEditor.vue @@ -32,11 +32,16 @@ import { EDITOR_SWITCH_TO_COMPLEX, } from "translator"; -const EDITOR_MODE_KEY = "editorMode"; -const kind = ref<"simple" | "rich">("simple"); -const value = defineModel({ required: true }); +enum EditorKind { + SIMPLE = "simple", + RICH = "rich", +} -const isSimple = computed(() => kind.value === "simple"); +const EDITOR_MODE_KEY = "editorMode"; +const kind = ref(EditorKind.SIMPLE); +const value = defineModel({ required: true }); + +const isSimple = computed(() => kind.value === EditorKind.SIMPLE); const toggleButtonClass = computed(() => { return { @@ -47,19 +52,20 @@ const toggleButtonClass = computed(() => { }); const toggleEditor = () => { - let newValue; - - newValue = kind.value === "simple" ? "rich" : "simple"; - kind.value = "rich"; + const newValue = + kind.value === EditorKind.SIMPLE ? EditorKind.RICH : EditorKind.SIMPLE; + kind.value = newValue; window.localStorage.setItem(EDITOR_MODE_KEY, newValue); - window.dispatchEvent(new Event("toggleEditorKind")); }; const onKindChange = function (/* event: StorageEvent | Event */) { const newValue = window.localStorage.getItem(EDITOR_MODE_KEY); - if (null === newValue || !(newValue === "rich" || newValue === "simple")) { + if ( + null === newValue || + !(newValue === EditorKind.RICH || newValue === EditorKind.SIMPLE) + ) { throw "invalid new value: " + newValue; } @@ -72,7 +78,10 @@ onMounted(function () { const storage = window.localStorage; const savedKind = storage.getItem(EDITOR_MODE_KEY); - if (null !== kind.value && (savedKind === "simple" || savedKind === "rich")) { + if ( + null !== kind.value && + (savedKind === EditorKind.SIMPLE || savedKind === EditorKind.RICH) + ) { kind.value = savedKind; }