From 80209790a848a4cc8e554ef0e015e86c6e118c78 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Thu, 7 Jan 2021 15:33:53 -0700 Subject: [PATCH] Sync state upon game rejoin --- web/src/views/CreateJoin.vue | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/web/src/views/CreateJoin.vue b/web/src/views/CreateJoin.vue index 92d4ea3..39db72d 100644 --- a/web/src/views/CreateJoin.vue +++ b/web/src/views/CreateJoin.vue @@ -97,11 +97,42 @@ export default { this.$store.commit(`view`, `lobby`); }, GameRejoined(data) { + /** + * data = { + * status: integer, + * ingame: boolean, + * role: role, + * team: team, + * is_host: boolean, + * players: Player[], + * chosen_object: string, + * hand: string[], + * answers: { + * team_1: string[], + * team_2: string[], + * }, + * }, + */ + console.log(data) if (!(200 <= data.status && data.status < 300)) { this.$emit(`error`, data); return; }; - // TODO -> Update all data that is received from the server + this.$store.commit(`resetState`); + this.$store.commit(`player`, { + name: this.name, + host: data.is_host, + role: data.role, + team: data.team, + }); + this.$store.commit(`setObject`, data.chosen_object); + this.$store.commit(`view`, data.ingame ? `in-game` : `lobby`); + this.$store.commit(`setAnswers`, data.answers); + this.$store.commit(`playerList`, data.players); + this.$store.commit(`replaceHand`, data.hand); + + history.replaceState(null, ``, `?game=${this.game_code}`); + this.$store.commit(`gameCode`, this.game_code); }, }, mounted() {},