bugfix: debounce save quote API call
This commit is contained in:
parent
fa7806e276
commit
62b0f429d7
@ -25,7 +25,7 @@ const newQuote = ref({} as Quote)
|
||||
const createNewQuote = () => {
|
||||
showNewQuoteCard.value = false
|
||||
newQuote.value = {
|
||||
id: '',
|
||||
id: ':new:' + Date.now(),
|
||||
quote: '',
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ const editModeEnd = async () => {
|
||||
|
||||
const saveQuote = async () => {
|
||||
if (props.quote.quote) {
|
||||
useEngine().saveQuote(props.quote.id || ':new:', props.quote.quote)
|
||||
await useEngine().saveQuote(props.quote.id, props.quote.quote)
|
||||
}
|
||||
|
||||
await editModeEnd()
|
||||
|
@ -1,10 +1,11 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"sirlab.de/go/knowyt/applicationConfig"
|
||||
"sirlab.de/go/knowyt/game"
|
||||
"sirlab.de/go/knowyt/user"
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewApplication(config applicationConfig.ApplicationConfig) (*Application, error) {
|
||||
@ -13,6 +14,7 @@ func NewApplication(config applicationConfig.ApplicationConfig) (*Application, e
|
||||
users: make(map[string]*user.User),
|
||||
games: make(map[string]*game.Game),
|
||||
playerATime: make(map[string]time.Time),
|
||||
debounceMap: make(map[string]bool),
|
||||
}
|
||||
|
||||
if err := app.loadUsers(); err != nil {
|
||||
|
@ -2,9 +2,10 @@ package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"sirlab.de/go/knowyt/game"
|
||||
"sirlab.de/go/knowyt/user"
|
||||
)
|
||||
@ -26,7 +27,8 @@ func (app *Application) SaveQuote(usr *user.User, w http.ResponseWriter, r *http
|
||||
|
||||
quoteText := r.URL.Query().Get("quote")
|
||||
quoteId := r.URL.Query().Get("id")
|
||||
if quoteId == ":new:" {
|
||||
if quoteId[:5] == ":new:" {
|
||||
if app.debounceQuote(usr.GetId() + ":" + quoteId) {
|
||||
quoteNewUuid := uuid.NewString()
|
||||
err = gm.CreateQuote(
|
||||
app.getQuoteFileNameFromId(gm, quoteNewUuid),
|
||||
@ -34,6 +36,7 @@ func (app *Application) SaveQuote(usr *user.User, w http.ResponseWriter, r *http
|
||||
quoteNewUuid,
|
||||
quoteText,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
err = gm.SaveQuote(
|
||||
app.getQuoteFileNameFromId(gm, quoteId),
|
||||
@ -58,3 +61,11 @@ func (app *Application) getQuoteFileNameFromId(gm *game.Game, id string) string
|
||||
quoteFileNameShort := id + ".json"
|
||||
return path.Join(gameDirName, "quotes", quoteFileNameShort)
|
||||
}
|
||||
|
||||
func (app *Application) debounceQuote(id string) bool {
|
||||
if app.debounceMap[id] {
|
||||
return false
|
||||
}
|
||||
app.debounceMap[id] = true
|
||||
return true
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"sirlab.de/go/knowyt/applicationConfig"
|
||||
"sirlab.de/go/knowyt/game"
|
||||
"sirlab.de/go/knowyt/user"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
@ -14,4 +15,5 @@ type Application struct {
|
||||
users map[string]*user.User
|
||||
games map[string]*game.Game
|
||||
playerATime map[string]time.Time
|
||||
debounceMap map[string]bool
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"sirlab.de/go/knowyt/quote"
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user