From e60def422650b6f8c15df2ba9413116973baa60a Mon Sep 17 00:00:00 2001 From: Dave Date: Wed, 27 Jan 2021 19:41:28 +0000 Subject: [PATCH] creating an action to store player pronoun in state and persist the data in local storage --- src/components/Player.vue | 12 ++++++------ src/store/modules/players.js | 6 ++++++ src/store/persistence.js | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index 3a3e864..4e5fdf1 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -240,12 +240,12 @@ export default { }, methods: { changePronoun() { - if (this.session.isSpectator) return; - const pronoun = - prompt("Player preffered pronouns", this.player.pronoun) || - this.player.pronoun; - this.updatePlayer("pronoun", pronoun, true); - this.$emit("trigger", ["updatePlayer", this.player, "pronoun", pronoun]); + const pronoun = prompt("Player preffered pronouns", this.player.pronoun); + this.$store.commit("players/setPronoun", { + player: this.player, + pronoun + }); + this.isMenuOpen = false; }, toggleStatus() { if (this.grimoire.isPublic) { diff --git a/src/store/modules/players.js b/src/store/modules/players.js index 83bd351..a04879b 100644 --- a/src/store/modules/players.js +++ b/src/store/modules/players.js @@ -107,6 +107,12 @@ const mutations = { state.players[index][property] = value; } }, + setPronoun(state, { player, pronoun }) { + const index = state.players.indexOf(player); + if (index >= 0) { + state.players[index].pronoun = pronoun; + } + }, add(state, name) { state.players.push({ ...NEWPLAYER, diff --git a/src/store/persistence.js b/src/store/persistence.js index fbd22ab..a0282fe 100644 --- a/src/store/persistence.js +++ b/src/store/persistence.js @@ -122,6 +122,7 @@ module.exports = store => { case "players/set": case "players/swap": case "players/move": + case "players/setPronoun": if (state.players.players.length) { localStorage.setItem( "players",