bugfix: bad event handling could create duplicate quotes on save

This commit is contained in:
Settel 2022-03-10 10:15:07 +01:00
parent ff38a5dce3
commit afd88e82cb
4 changed files with 30 additions and 33 deletions

View File

@ -1,19 +1,9 @@
<template> <template>
<div class="add-new-quote"> <div class="add-new-quote">
<button class="add-new-quote__button" @click="newQuote">+</button> <button class="add-new-quote__button" @click="$emit('createQuote')">+</button>
</div> </div>
</template> </template>
<script>
export default {
methods: {
newQuote() {
this.$nuxt.$emit('create-quote')
},
},
}
</script>
<style lang="scss"> <style lang="scss">
@import '~/assets/css/components'; @import '~/assets/css/components';

View File

@ -31,10 +31,10 @@ export default {
props: ['quote'], props: ['quote'],
methods: { methods: {
save() { save() {
this.$nuxt.$emit('save-quote', this.quote) this.$emit('saveQuote', this.quote)
}, },
close() { close() {
this.$nuxt.$emit('close-quote') this.$emit('close')
}, },
}, },
} }

View File

@ -1,11 +1,21 @@
<template> <template>
<div> <div>
<CollectQuotesExplain /> <CollectQuotesExplain />
<AddNewQuote v-if="quotes.length > 0"/> <AddNewQuote v-if="quotes.length > 0" @createQuote="createQuote"/>
<NoQuotesYet v-if="quotes.length == 0" /> <NoQuotesYet v-if="quotes.length == 0" />
<QuoteListItem v-for="quote in quotes" :key="quote.id" :quote="quote" /> <QuoteListItem
<AddNewQuote /> v-for="quote in quotes"
<CollectQuote v-if="showCollectQuoteDialog" :quote="collectQuote" /> :key="quote.id"
:quote="quote"
@editQuote="editQuote"
/>
<AddNewQuote @createQuote="createQuote" />
<CollectQuote
v-if="showCollectQuoteDialog"
:quote="collectQuote"
@close="closeCollectQuoteDialog"
@saveQuote="saveQuote"
/>
</div> </div>
</template> </template>
@ -27,32 +37,29 @@ export default {
return quotes return quotes
}, },
}, },
created() { methods: {
this.$nuxt.$on('close-quote', () => { closeCollectQuoteDialog() {
this.showCollectQuoteDialog = false this.showCollectQuoteDialog = false
}) },
editQuote(quote) {
this.$nuxt.$on('edit-quote', (quote) => {
this.showCollectQuoteDialog = true this.showCollectQuoteDialog = true
this.collectQuote = { this.collectQuote = {
id: quote.id, id: quote.id,
quote: quote.quote, quote: quote.quote,
} }
}) },
async saveQuote(quote) {
this.$nuxt.$on('create-quote', (quote) => { this.$engine.saveQuote(quote.id, quote.quote)
await this.$engine.getMyQuotes()
this.showCollectQuoteDialog = false
},
createQuote() {
this.showCollectQuoteDialog = true this.showCollectQuoteDialog = true
this.collectQuote = { this.collectQuote = {
id: ':new:', id: ':new:',
quote: '', quote: '',
} }
}) },
this.$nuxt.$on('save-quote', async (quote) => {
this.$engine.saveQuote(quote.id, quote.quote)
await this.$engine.getMyQuotes()
this.showCollectQuoteDialog = false
})
}, },
async fetch() { async fetch() {
await this.$engine.getMyQuotes() await this.$engine.getMyQuotes()

View File

@ -17,7 +17,7 @@ export default {
props: ['quote'], props: ['quote'],
methods: { methods: {
async edit() { async edit() {
this.$nuxt.$emit('edit-quote', this.quote) this.$emit('editQuote', this.quote)
}, },
async remove() { async remove() {
if (confirm('Eintrag wirklich löschen?')) { if (confirm('Eintrag wirklich löschen?')) {