Save and load default edit type
authorAdam Dullage <redacted>
Wed, 15 May 2024 11:43:59 +0000 (12:43 +0100)
committerAdam Dullage <redacted>
Wed, 15 May 2024 11:43:59 +0000 (12:43 +0100)
client/components/toastui/ToastEditor.vue
client/views/Note.vue

index 49faaabac15e070510c2dbc79aa270e15ea2e57a..fe5e9df984cf2cb666939bd3b84fe532e7a5a0e3 100644 (file)
@@ -10,6 +10,10 @@ import baseOptions from "./baseOptions.js";
 
 const props = defineProps({
   initialValue: String,
+  initialEditType: {
+    type: String,
+    default: "markdown",
+  },
 });
 
 const editorElement = ref();
@@ -20,6 +24,7 @@ onMounted(() => {
     ...baseOptions,
     el: editorElement.value,
     initialValue: props.initialValue,
+    initialEditType: props.initialEditType,
   });
 });
 
@@ -27,7 +32,11 @@ function getMarkdown() {
   return toastEditor.getMarkdown();
 }
 
-defineExpose({ getMarkdown });
+function isWysiwygMode() {
+  return toastEditor.isWysiwygMode();
+}
+
+defineExpose({ getMarkdown, isWysiwygMode });
 </script>
 
 <style>
index b4d89f1dffb4d987db3e2e824ec15799ddeb61a8..2a821212ea415ce0a78f61c557492efd9d544d62 100644 (file)
@@ -75,6 +75,7 @@
         v-if="editMode"
         ref="toastEditor"
         :initialValue="note.content"
+        :initialEditType="loadDefaultEditorMode()"
       />
     </div>
   </LoadingIndicator>
@@ -195,6 +196,19 @@ function setBeforeUnloadConfirmation(enable = true) {
   }
 }
 
+function saveDefaultEditorMode() {
+  const isWysiwygMode = toastEditor.value.isWysiwygMode();
+  localStorage.setItem(
+    "defaultEditorMode",
+    isWysiwygMode ? "wysiwyg" : "markdown",
+  );
+}
+
+function loadDefaultEditorMode() {
+  const defaultWysiwygMode = localStorage.getItem("defaultEditorMode");
+  return defaultWysiwygMode || "markdown";
+}
+
 // Button Handlers
 function editHandler() {
   setBeforeUnloadConfirmation(true);
@@ -218,6 +232,9 @@ function cancelHandler() {
 }
 
 function saveHandler() {
+  // Save Default Editor Mode
+  saveDefaultEditorMode();
+
   // Empty Title Validation
   if (!newTitle.value) {
     toast.add(
@@ -232,6 +249,7 @@ function saveHandler() {
     return;
   }
 
+  // Save Note
   let newContent = toastEditor.value.getMarkdown();
   if (isNewNote.value) {
     saveNew(newTitle.value, newContent);
git clone https://git.99rst.org/PROJECT