Commit fb642155 authored by Fatih Acet's avatar Fatih Acet

Fix empty markdown render request.

parent 7e82e45d
...@@ -47,22 +47,29 @@ ...@@ -47,22 +47,29 @@
toggleMarkdownPreview() { toggleMarkdownPreview() {
this.previewMarkdown = !this.previewMarkdown; this.previewMarkdown = !this.previewMarkdown;
if (!this.previewMarkdown) {
this.markdownPreview = '';
} else {
this.markdownPreviewLoading = true;
this.$http.post(
this.markdownPreviewPath,
{
/* /*
Can't use `$refs` as the component is technically in the parent component Can't use `$refs` as the component is technically in the parent component
so we access the VNode & then get the element so we access the VNode & then get the element
*/ */
text: this.$slots.textarea[0].elm.value, const text = this.$slots.textarea[0].elm.value;
},
) if (!this.previewMarkdown) {
this.markdownPreview = '';
} else {
if (text) {
this.markdownPreviewLoading = true;
this.$http.post(this.markdownPreviewPath, { text })
.then(resp => resp.json()) .then(resp => resp.json())
.then((data) => { .then((data) => {
this.renderMarkdown(data);
})
.catch(() => new Flash('Error loading markdown preview'));
} else {
this.renderMarkdown();
}
}
},
renderMarkdown(data = {}) {
this.markdownPreviewLoading = false; this.markdownPreviewLoading = false;
this.markdownPreview = data.body || 'Nothing to preview.'; this.markdownPreview = data.body || 'Nothing to preview.';
...@@ -74,9 +81,6 @@ ...@@ -74,9 +81,6 @@
this.$nextTick(() => { this.$nextTick(() => {
$(this.$refs['markdown-preview']).renderGFM(); $(this.$refs['markdown-preview']).renderGFM();
}); });
})
.catch(() => new Flash('Error loading markdown preview'));
}
}, },
}, },
mounted() { mounted() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment