bugfix: reset stores when user logs out
bugfix: ignore pending request that do not elong to current game
This commit is contained in:
parent
258067cf84
commit
582922a21a
@ -21,9 +21,9 @@ type EngineResponse = {
|
||||
|
||||
const { $t } = useI18n({
|
||||
'connection-broken': { en: 'connection to server broken.', de: 'Verbindung zum Server ist unterbrochen.' },
|
||||
'retrying': { en: 'retrying', de: 'verbinde erneut'},
|
||||
})
|
||||
|
||||
'retrying': { en: 'retrying', de: 'verbinde erneut' },
|
||||
})
|
||||
|
||||
export async function fetchUpdate(this: EngineContext) {
|
||||
if (this.shouldStop || !this.isActive) {
|
||||
useAlert().clearAlert()
|
||||
@ -44,10 +44,16 @@ export async function fetchUpdate(this: EngineContext) {
|
||||
throw Error('unexpected response from /api/sync')
|
||||
}
|
||||
|
||||
if (response.game.id != userInfoStore.gameId) {
|
||||
// happens when user changes game and an old request is still pending
|
||||
console.warn('response gameId does not match current gameId')
|
||||
return
|
||||
}
|
||||
|
||||
this.version = parseInt(response.version)
|
||||
this.isConnected.value = true
|
||||
this.retry.value = 0
|
||||
|
||||
|
||||
useAlert().clearAlert()
|
||||
useEngineStore().setJson(response)
|
||||
useGameinfoStore().setGameinfo(response.game)
|
||||
@ -66,7 +72,7 @@ export async function fetchUpdate(this: EngineContext) {
|
||||
this.isConnected.value = false
|
||||
this.retry.value++
|
||||
useAlert().setAlert([
|
||||
$t('connection-broken'),
|
||||
$t('connection-broken'),
|
||||
this.retry.value > 0 ? $t('retrying') + '...'.slice(0, this.retry.value % 4) : ''
|
||||
])
|
||||
|
||||
|
@ -1,5 +1,9 @@
|
||||
import { useUserinfoStore, Userinfo } from "@/stores/UserinfoStore"
|
||||
import useI18n from "./useI18n"
|
||||
import { useUserinfoStore, Userinfo } from '@/stores/UserinfoStore'
|
||||
import { useEngineStore } from '@/stores/EngineStore'
|
||||
import { useGameinfoStore } from '@/stores/GameinfoStore'
|
||||
import { usePlayersStore } from '@/stores/PlayersStore'
|
||||
import { useRoundStore } from '@/stores/RoundStore'
|
||||
import useI18n from './useI18n'
|
||||
import { $fetch } from 'ohmyfetch'
|
||||
|
||||
export type AllowRole = '' | 'player' | 'gamemaster' | 'admin'
|
||||
@ -49,6 +53,11 @@ export default (): useAuth => {
|
||||
|
||||
logout: async (): Promise<void> => {
|
||||
await $fetch('/api/logout')
|
||||
useEngineStore().reset()
|
||||
useGameinfoStore().reset()
|
||||
usePlayersStore().reset()
|
||||
useUserinfoStore().reset()
|
||||
useRoundStore().reset()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,8 @@ export const useEngineStore = defineStore('EngineStore', {
|
||||
setJson(json: any): void {
|
||||
this.json = json
|
||||
},
|
||||
reset(): void {
|
||||
this.json = {}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -33,5 +33,13 @@ export const useGameinfoStore = defineStore('GameinfoStore', {
|
||||
setGameinfo(gameInfo: Gameinfo): void {
|
||||
this.gameInfo = gameInfo
|
||||
},
|
||||
reset(): void {
|
||||
this.gameInfo = {
|
||||
id: '',
|
||||
name: '',
|
||||
state: '',
|
||||
phase: '',
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -12,5 +12,8 @@ export const usePlayersStore = defineStore('PlayersStore', {
|
||||
players = players || []
|
||||
this.players.splice(0, this.players.length, ...players)
|
||||
},
|
||||
reset(): void {
|
||||
this.players.splice(0, 0)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -24,5 +24,16 @@ export const useRoundStore = defineStore('RoundStore', {
|
||||
this.round.revelation.votes = round.revelation?.votes || {} as RevelationVotes
|
||||
this.round.revelation.sources = round.revelation?.sources || {} as RevelationSources
|
||||
},
|
||||
reset(): void {
|
||||
this.round = {
|
||||
quote: '',
|
||||
sources: [],
|
||||
selections: {},
|
||||
revelation: {
|
||||
votes: {},
|
||||
sources: {},
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -34,5 +34,15 @@ export const useUserinfoStore = defineStore('UserinfoStore', {
|
||||
setUserInfo(userInfo: Userinfo): void {
|
||||
this.userInfo = userInfo
|
||||
},
|
||||
reset(): void {
|
||||
this.userInfo = {
|
||||
id: '',
|
||||
name: '',
|
||||
role: '',
|
||||
game: '',
|
||||
lang: 'en',
|
||||
isCameo: '',
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user