Browse Source

Fix redirect after new campaign creation

Kailash Nadh 5 years ago
parent
commit
f2030a1768

+ 3 - 1
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);
   },
 };

+ 9 - 2
frontend/src/components/Editor.vue

@@ -29,6 +29,7 @@
       :disabled="disabled"
       placeholder="Content here"
       @change="onEditorChange($event)"
+      @ready="onEditorReady($event)"
     />
 
     <!-- raw html editor //-->
@@ -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);
     },
   },
 

+ 11 - 8
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(() => {