Commit fb642155 authored by Fatih Acet's avatar Fatih Acet

Fix empty markdown render request.

parent 7e82e45d
...@@ -47,36 +47,40 @@ ...@@ -47,36 +47,40 @@
toggleMarkdownPreview() { toggleMarkdownPreview() {
this.previewMarkdown = !this.previewMarkdown; this.previewMarkdown = !this.previewMarkdown;
/*
Can't use `$refs` as the component is technically in the parent component
so we access the VNode & then get the element
*/
const text = this.$slots.textarea[0].elm.value;
if (!this.previewMarkdown) { if (!this.previewMarkdown) {
this.markdownPreview = ''; this.markdownPreview = '';
} else { } else {
this.markdownPreviewLoading = true; if (text) {
this.$http.post( this.markdownPreviewLoading = true;
this.markdownPreviewPath, this.$http.post(this.markdownPreviewPath, { text })
{ .then(resp => resp.json())
/* .then((data) => {
Can't use `$refs` as the component is technically in the parent component this.renderMarkdown(data);
so we access the VNode & then get the element })
*/ .catch(() => new Flash('Error loading markdown preview'));
text: this.$slots.textarea[0].elm.value, } else {
}, this.renderMarkdown();
) }
.then(resp => resp.json()) }
.then((data) => { },
this.markdownPreviewLoading = false; renderMarkdown(data = {}) {
this.markdownPreview = data.body || 'Nothing to preview.'; this.markdownPreviewLoading = false;
this.markdownPreview = data.body || 'Nothing to preview.';
if (data.references) {
this.referencedCommands = data.references.commands;
this.referencedUsers = data.references.users;
}
this.$nextTick(() => { if (data.references) {
$(this.$refs['markdown-preview']).renderGFM(); this.referencedCommands = data.references.commands;
}); this.referencedUsers = data.references.users;
})
.catch(() => new Flash('Error loading markdown preview'));
} }
this.$nextTick(() => {
$(this.$refs['markdown-preview']).renderGFM();
});
}, },
}, },
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