From f2030a1768062697c9924d64a6ddf27a55b8294a Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 5 Jul 2020 14:08:30 +0530 Subject: [PATCH] Fix redirect after new campaign creation --- frontend/src/components/CampaignPreview.vue | 4 +++- frontend/src/components/Editor.vue | 11 +++++++++-- frontend/src/views/Campaign.vue | 19 +++++++++++-------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/CampaignPreview.vue b/frontend/src/components/CampaignPreview.vue index 18415a2..4e83416 100644 --- a/frontend/src/components/CampaignPreview.vue +++ b/frontend/src/components/CampaignPreview.vue @@ -86,7 +86,9 @@ export default { mounted() { setTimeout(() => { - this.$refs.form.submit(); + if (this.$refs.form) { + this.$refs.form.submit(); + } }, 100); }, }; diff --git a/frontend/src/components/Editor.vue b/frontend/src/components/Editor.vue index 68c9a91..307b894 100644 --- a/frontend/src/components/Editor.vue +++ b/frontend/src/components/Editor.vue @@ -29,6 +29,7 @@ :disabled="disabled" placeholder="Content here" @change="onEditorChange($event)" + @ready="onEditorReady($event)" /> @@ -142,6 +143,13 @@ export default { ); }, + onEditorReady() { + // Hack to focus the editor on page load. + this.$nextTick(() => { + window.setTimeout(() => this.$refs.quill.quill.focus(), 100); + }); + }, + onEditorChange() { // The parent's v-model gets { contentType, body }. this.$emit('input', { contentType: this.form.format, body: this.form.body }); @@ -156,8 +164,7 @@ export default { }, onMediaSelect(m) { - this.$refs.quill.quill - .insertEmbed(10, 'image', m.uri); + this.$refs.quill.quill.insertEmbed(10, 'image', m.uri); }, }, diff --git a/frontend/src/views/Campaign.vue b/frontend/src/views/Campaign.vue index 7d7c23f..3de8fb5 100644 --- a/frontend/src/views/Campaign.vue +++ b/frontend/src/views/Campaign.vue @@ -181,7 +181,7 @@ export default Vue.extend({ }, getCampaign(id) { - this.$api.getCampaign(id).then((r) => { + return this.$api.getCampaign(id).then((r) => { this.data = r.data; this.form = { ...this.form, ...r.data }; @@ -237,12 +237,12 @@ export default Vue.extend({ }; this.$api.createCampaign(data).then((r) => { - this.$router.push({ name: 'campaign', params: { id: r.data.id } }); + this.$router.push({ name: 'campaign', hash: '#content', params: { id: r.data.id } }); - this.data = r.data; - this.isEditing = true; - this.isNew = false; - this.activeTab = 1; + // this.data = r.data; + // this.isEditing = true; + // this.isNew = false; + // this.activeTab = 1; }); return false; }, @@ -326,7 +326,6 @@ export default Vue.extend({ mounted() { const { id } = this.$route.params; - // New campaign. if (id === 'new') { this.isNew = true; @@ -355,7 +354,11 @@ export default Vue.extend({ // Fetch campaign. if (this.isEditing) { - this.getCampaign(id); + this.getCampaign(id).then(() => { + if (this.$route.hash === '#content') { + this.activeTab = 1; + } + }); } this.$nextTick(() => {