update list of quotes after create/delete
This commit is contained in:
parent
a6b6d1dfd6
commit
d70f98bf48
@ -14,18 +14,19 @@
|
|||||||
export default {
|
export default {
|
||||||
props: ['quote'],
|
props: ['quote'],
|
||||||
methods: {
|
methods: {
|
||||||
edit() {
|
async edit() {
|
||||||
console.log('edit')
|
await this.save()
|
||||||
this.save()
|
|
||||||
},
|
},
|
||||||
save() {
|
async save() {
|
||||||
console.log('save')
|
this.$engine.createQuote(this.quote.quote)
|
||||||
// this.$engine.createQuote(this.quote.quote)
|
|
||||||
// this.$engine.saveQuote(this.quote.id, this.quote.quote)
|
// this.$engine.saveQuote(this.quote.id, this.quote.quote)
|
||||||
// this.$engine.removeQuote(this.quote.id)
|
await this.$engine.getMyQuotes()
|
||||||
},
|
},
|
||||||
remove() {
|
async remove() {
|
||||||
console.log('remove')
|
if (confirm('Eintrag wirklich löschen?')) {
|
||||||
|
this.$engine.removeQuote(this.quote.id)
|
||||||
|
await this.$engine.getMyQuotes()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,18 @@ package game
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"sirlab.de/go/knyt/quote"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gm *Game) RemoveQuote(fileName, usrId, quoteId string) error {
|
func (gm *Game) RemoveQuote(fileName, usrId, quoteId string) error {
|
||||||
if quote, err := gm.getQuoteById(quoteId); err != nil {
|
if qu, err := gm.getQuoteById(quoteId); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
if quote.GetSourceId() != usrId {
|
if qu.GetSourceId() != usrId {
|
||||||
return fmt.Errorf("usrId does not match quote source id")
|
return fmt.Errorf("usrId does not match quote source id")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gm.removeQuoteFromList(qu)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := os.Remove(fileName)
|
err := os.Remove(fileName)
|
||||||
@ -21,3 +24,10 @@ func (gm *Game) RemoveQuote(fileName, usrId, quoteId string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gm *Game) removeQuoteFromList(qu *quote.Quote) {
|
||||||
|
gm.mu.Lock()
|
||||||
|
defer gm.mu.Unlock()
|
||||||
|
|
||||||
|
delete(gm.quotes, qu.GetId())
|
||||||
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
func (gm *Game) CreateQuote(fileName, usrId, quoteId, quoteText string) error {
|
func (gm *Game) CreateQuote(fileName, usrId, quoteId, quoteText string) error {
|
||||||
qu := quote.NewQuote(quoteId, usrId, quoteText)
|
qu := quote.NewQuote(quoteId, usrId, quoteText)
|
||||||
|
gm.AddQuote(qu)
|
||||||
return qu.Save(fileName)
|
return qu.Save(fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user