From a760949b846a4ce5ceae81cadc64e9c8fc93553c Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Wed, 19 Sep 2018 14:13:31 +0200 Subject: [PATCH] Make modal handling a bit more generic --- client/src/App.vue | 7 +- .../ContentBlockForm.vue} | 94 ++++++------------- .../NewContentBlockWizard.vue | 63 +++++++++++++ 3 files changed, 96 insertions(+), 68 deletions(-) rename client/src/components/{NewContentBlockWizard.vue => content-block-form/ContentBlockForm.vue} (67%) create mode 100644 client/src/components/content-block-form/NewContentBlockWizard.vue diff --git a/client/src/App.vue b/client/src/App.vue index 41fb07d8..82a9ad2b 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -1,6 +1,6 @@ @@ -9,7 +9,7 @@ import DefaultLayout from '@/layouts/DefaultLayout'; import SimpleLayout from '@/layouts/SimpleLayout'; import Modal from '@/components/Modal'; - import NewContentBlockWizard from '@/components/NewContentBlockWizard'; + import NewContentBlockWizard from '@/components/content-block-form/NewContentBlockWizard'; export default { name: 'App', @@ -27,9 +27,6 @@ }, showModal() { return this.$store.state.showModal - }, - modalComponent() { - return 'new-content-block-wizard' } }, diff --git a/client/src/components/NewContentBlockWizard.vue b/client/src/components/content-block-form/ContentBlockForm.vue similarity index 67% rename from client/src/components/NewContentBlockWizard.vue rename to client/src/components/content-block-form/ContentBlockForm.vue index 27df6368..a2ede60b 100644 --- a/client/src/components/NewContentBlockWizard.vue +++ b/client/src/components/content-block-form/ContentBlockForm.vue @@ -1,15 +1,16 @@ @@ -49,9 +50,9 @@ import TextForm from '@/components/content-forms/TextForm'; import TrashIcon from '@/components/icons/TrashIcon'; - import NEW_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/addContentBlock.gql'; - export default { + props: ['content-block'], + components: { Modal, ContentBlockElementChooserWidget, @@ -66,6 +67,13 @@ TrashIcon }, + data() { + return { + error: false, + localContentBlock: Object.assign({}, this.contentBlock) + } + }, + methods: { type(element) { switch (element.type) { @@ -85,8 +93,8 @@ return 'content-block-element-chooser-widget' }, _updateProperty(value, index, key) { - this.elements.splice(index, 1, { - ...this.elements[index], + this.localContentBlock.elements.splice(index, 1, { + ...this.localContentBlock.elements[index], [key]: value }); }, @@ -94,6 +102,7 @@ this._updateProperty(value, index, 'url') }, changeLinkText(value, index) { + // debugger; this._updateProperty(value, index, 'text') }, changeVideoUrl(value, index) { @@ -106,13 +115,13 @@ this._updateProperty(value, index, 'text') }, removeElement(index) { - this.elements.splice(index, 1); + this.localContentBlock.elements.splice(index, 1); }, addElement(index) { - this.elements.splice(index + 1, 0, {}) + this.localContentBlock.elements.splice(index + 1, 0, {}) }, updateTitle(title) { - this.title = title; + this.localContentBlock.title = title; this.error = false; }, changeType(index, type) { @@ -147,55 +156,14 @@ break; } - this.elements.splice(index, 1, el); + this.localContentBlock.elements.splice(index, 1, el); }, - hideModal() { - this.$store.dispatch('resetContentBlock'); - this.$store.dispatch('hideModal'); - }, - saveContentBlock() { - if (!this.title) { + save() { + if (!this.localContentBlock.title) { this.error = true; return false; } - this.$apollo.mutate({ - mutation: NEW_CONTENT_BLOCK_MUTATION, - variables: { - input: { - contentBlock: { - title: this.title, - contents: this.elements.filter(value => Object.keys(value).length > 0) - }, - after: this.$store.state.contentBlockPosition.after, - parent: this.$store.state.contentBlockPosition.parent - } - }, - update: () => { - this.$store.dispatch('updateContentBlocks'); - this.hideModal(); - } - }); - } - }, - - data() { - return { - title: '', - elements: [ - {} - // { - // type: 'image' - // }, - // { - // type: 'video', - // url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' - // }, - // { - // type: 'video', - // url: 'https://vimeo.com/267384185' - // } - ], - error: false + this.$emit('save', this.localContentBlock); } } } @@ -204,7 +172,7 @@