From fcc6712e231876d734e6c1f248b62fedefea222e Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sat, 19 Dec 2020 18:00:44 -0700 Subject: [PATCH] Move the questions storage from the hand data object to the VueX store --- web/src/components/Hand.vue | 29 +++++++++++++++++++---------- web/src/store/index.js | 1 + 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/web/src/components/Hand.vue b/web/src/components/Hand.vue index 837487d..096d8b6 100644 --- a/web/src/components/Hand.vue +++ b/web/src/components/Hand.vue @@ -23,9 +23,6 @@ export default { name: `PlayerHand`, components: {}, - data() {return { - questions: [], - }}, computed: { userRole() { return this.$store.state.role; @@ -45,6 +42,9 @@ export default { return `Unknown Role` } }, + questions() { + return this.$store.state.questions; + } }, methods: { sendCard(cardIndex) { @@ -68,7 +68,7 @@ export default { // Discard the rest of the writer's hand if (this.isWriter) { - this.questions = []; + this.$store.state.questions = []; }; // TODO -> send data to server @@ -76,19 +76,28 @@ export default { } }, sockets: { - NewCard(data) { + UpdateHand(data) { /** * Triggered when the client gets a new card for their hand, if the * "from" property is set to either of the * * data = { - * text: string, - * from: "guesser" | "writer" | "deck", - * team: 1 | 2, + * questions: String[], + * mode: "append"|"replace", * } */ - console.debug(`Got a new card from the ${data.from} on team ${data.team}`); - this.questions.push(data.text); + console.debug(`Updating hand.`); + console.debug(data); + switch (data.mode) { + case `append`: + // TODO -> Implement appending + break; + case `replace`: + this.$store.state.questions = data.questions; + break; + default: + console.error(`Server returned an unsupported mode.`); + }; }, }, } diff --git a/web/src/store/index.js b/web/src/store/index.js index a13bac0..e60793f 100644 --- a/web/src/store/index.js +++ b/web/src/store/index.js @@ -43,6 +43,7 @@ export default new Vuex.Store({ id: null, players: [], chosen_object: null, + questions: [], }, getters: { teamName(state) {