]> BookStack Code Mirror - bookstack/blobdiff - resources/js/components/markdown-editor.js
Added test to preference boolean endpoint
[bookstack] / resources / js / components / markdown-editor.js
index 162dd6771f920d96ad7c20318589de8fd1054bdd..373fedf487db79c5d3eb715304efb8f95f2d39d4 100644 (file)
@@ -26,7 +26,8 @@ export class MarkdownEditor extends Component {
             text: {
                 serverUploadLimit: this.serverUploadLimitText,
                 imageUploadError: this.imageUploadErrorText,
-            }
+            },
+            settings: this.loadSettings(),
         }).then(editor => {
             this.editor = editor;
             this.setupListeners();
@@ -81,7 +82,7 @@ export class MarkdownEditor extends Component {
             const name = actualInput.getAttribute('name');
             const value = actualInput.getAttribute('value');
             window.$http.patch('/preferences/update-boolean', {name, value});
-            // TODO - Update state locally
+            this.editor.settings.set(name, value === 'true');
         });
 
         // Refresh CodeMirror on container resize
@@ -90,6 +91,17 @@ export class MarkdownEditor extends Component {
         observer.observe(this.elem);
     }
 
+    loadSettings() {
+        const settings = {};
+        const inputs = this.settingContainer.querySelectorAll('input[type="hidden"]');
+
+        for (const input of inputs) {
+            settings[input.getAttribute('name')] = input.value === 'true';
+        }
+
+        return settings;
+    }
+
     scrollToTextIfNeeded() {
         const queryParams = (new URL(window.location)).searchParams;
         const scrollText = queryParams.get('content-text');