From 07de00ce5b30287a791cd51be8ada8796dec03b1 Mon Sep 17 00:00:00 2001 From: Gamebrary Date: Tue, 18 Aug 2020 15:01:16 -0700 Subject: [PATCH] rename mutations as well --- src/App.vue | 10 +- src/components/Board/AddList.vue | 2 +- src/components/Game/GameModal.vue | 10 +- src/components/GameCards/GameCard.js | 2 +- src/components/LegacyBoard/LegacyAddList.vue | 2 +- .../LegacyBoard/LegacyBoardSettings.vue | 2 +- src/components/LegacyBoard/LegacyGameCard.js | 2 +- .../LegacyBoard/LegacyGameModal.vue | 9 +- .../LegacyBoard/LegacyListSettings.vue | 4 +- .../LegacyBoard/LegacyListSettings0.vue | 4 +- .../LegacyBoard/LegacyPlatformsList.vue | 2 +- src/components/Lists/ListSettings.vue | 4 +- src/components/Settings/BoardSettings.vue | 2 +- src/store/actions.js | 15 +- src/store/mutations.js | 201 ++++++++---------- 15 files changed, 134 insertions(+), 137 deletions(-) diff --git a/src/App.vue b/src/App.vue index 9f6da6c7..7d7469e7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -133,7 +133,7 @@ export default { this.loadWallpaper(); } } else { - this.$store.commit('SET_WALLPAPER_URL', ''); + this.$store.commit('SET_WALLPAPER_URL_LEGACY', ''); } }, }, @@ -181,10 +181,10 @@ export default { loadWallpaper() { const wallpaperRef = this.customWallpaper; - this.$store.commit('SET_WALLPAPER_URL', ''); + this.$store.commit('SET_WALLPAPER_URL_LEGACY', ''); storage.child(wallpaperRef).getDownloadURL().then((url) => { - this.$store.commit('SET_WALLPAPER_URL', url); + this.$store.commit('SET_WALLPAPER_URL_LEGACY', url); }); }, @@ -195,7 +195,7 @@ export default { .onSnapshot((doc) => { if (doc.exists) { const gameLists = doc.data(); - this.$store.commit('SET_GAME_LISTS', gameLists); + this.$store.commit('SET_GAME_LISTS_LEGACY', gameLists); } }); @@ -271,7 +271,7 @@ export default { .then((doc) => { if (doc.exists) { const data = doc.data(); - this.$store.commit('SET_GAME_LISTS', data); + this.$store.commit('SET_GAME_LISTS_LEGACY', data); } else { this.initList(); } diff --git a/src/components/Board/AddList.vue b/src/components/Board/AddList.vue index b33a8aaa..dd6ba50f 100644 --- a/src/components/Board/AddList.vue +++ b/src/components/Board/AddList.vue @@ -124,7 +124,7 @@ export default { this.saving = true; - this.$store.dispatch('ADD_LIST', list) + this.$store.dispatch('ADD_LIST_LEGACY', list) .then(() => { this.$bvToast.toast('List added', { variant: 'success', diff --git a/src/components/Game/GameModal.vue b/src/components/Game/GameModal.vue index ed41df40..f3682261 100644 --- a/src/components/Game/GameModal.vue +++ b/src/components/Game/GameModal.vue @@ -516,7 +516,7 @@ export default { }; // this.$emit('added'); - this.$store.commit('ADD_GAME', data); + this.$store.commit('ADD_GAME_LEGACY', data); this.$ga.event({ eventCategory: 'game', @@ -542,7 +542,7 @@ export default { gameId: this.game.id, }; - this.$store.commit('REMOVE_GAME', data); + this.$store.commit('REMOVE_GAME_LEGACY', data); this.$store .dispatch('SAVE_LIST_LEGACY', this.gameLists) @@ -574,6 +574,12 @@ export default { this.$bvToast.toast('Error loading game', { title: 'Error', variant: 'error' }); }); + + // avoid error when closing modal before game finishes loading + if (!this.game) { + return; + } + this.game = { ...this.game, ...game, diff --git a/src/components/GameCards/GameCard.js b/src/components/GameCards/GameCard.js index 1387164f..86d1399f 100644 --- a/src/components/GameCards/GameCard.js +++ b/src/components/GameCards/GameCard.js @@ -104,7 +104,7 @@ export default { }; this.$emit('added'); - this.$store.commit('ADD_GAME', data); + this.$store.commit('ADD_GAME_LEGACY', data); this.$ga.event({ eventCategory: 'game', diff --git a/src/components/LegacyBoard/LegacyAddList.vue b/src/components/LegacyBoard/LegacyAddList.vue index f9c3d3c5..3f79939a 100644 --- a/src/components/LegacyBoard/LegacyAddList.vue +++ b/src/components/LegacyBoard/LegacyAddList.vue @@ -124,7 +124,7 @@ export default { this.saving = true; - this.$store.commit('ADD_LIST', list); + this.$store.commit('ADD_LIST_LEGACY', list); this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists) .then(() => { diff --git a/src/components/LegacyBoard/LegacyBoardSettings.vue b/src/components/LegacyBoard/LegacyBoardSettings.vue index b1243603..33c6e9e1 100644 --- a/src/components/LegacyBoard/LegacyBoardSettings.vue +++ b/src/components/LegacyBoard/LegacyBoardSettings.vue @@ -92,7 +92,7 @@ export default { }, deleteBoard() { - this.$store.commit('REMOVE_PLATFORM'); + this.$store.commit('REMOVE_PLATFORM_LEGACY'); this.$store.dispatch('SAVE_LIST_NO_MERGE_LEGACY', this.gameLists) .then(() => { diff --git a/src/components/LegacyBoard/LegacyGameCard.js b/src/components/LegacyBoard/LegacyGameCard.js index 1387164f..86d1399f 100644 --- a/src/components/LegacyBoard/LegacyGameCard.js +++ b/src/components/LegacyBoard/LegacyGameCard.js @@ -104,7 +104,7 @@ export default { }; this.$emit('added'); - this.$store.commit('ADD_GAME', data); + this.$store.commit('ADD_GAME_LEGACY', data); this.$ga.event({ eventCategory: 'game', diff --git a/src/components/LegacyBoard/LegacyGameModal.vue b/src/components/LegacyBoard/LegacyGameModal.vue index 35a93f49..4b054156 100644 --- a/src/components/LegacyBoard/LegacyGameModal.vue +++ b/src/components/LegacyBoard/LegacyGameModal.vue @@ -516,7 +516,7 @@ export default { }; // this.$emit('added'); - this.$store.commit('ADD_GAME', data); + this.$store.commit('ADD_GAME_LEGACY', data); this.$ga.event({ eventCategory: 'game', @@ -542,7 +542,7 @@ export default { gameId: this.game.id, }; - this.$store.commit('REMOVE_GAME', data); + this.$store.commit('REMOVE_GAME_LEGACY', data); this.$store .dispatch('SAVE_LIST_LEGACY', this.gameLists) @@ -574,6 +574,11 @@ export default { this.$bvToast.toast('Error loading game', { title: 'Error', variant: 'error' }); }); + // avoid error when closing modal before game finishes loading + if (!this.game) { + return; + } + this.game = { ...this.game, ...game, diff --git a/src/components/LegacyBoard/LegacyListSettings.vue b/src/components/LegacyBoard/LegacyListSettings.vue index 31b73a96..eaced6f2 100644 --- a/src/components/LegacyBoard/LegacyListSettings.vue +++ b/src/components/LegacyBoard/LegacyListSettings.vue @@ -126,7 +126,7 @@ export default { }, async deleteList() { - this.$store.commit('REMOVE_LIST', this.listIndex); + this.$store.commit('REMOVE_LIST_LEGACY', this.listIndex); await this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists) .catch(() => { @@ -140,7 +140,7 @@ export default { }, async moveList(from, to) { - this.$store.commit('MOVE_LIST', { from, to }); + this.$store.commit('MOVE_LIST_LEGACY', { from, to }); await this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists) .catch(() => { diff --git a/src/components/LegacyBoard/LegacyListSettings0.vue b/src/components/LegacyBoard/LegacyListSettings0.vue index 12796020..1c3fff69 100644 --- a/src/components/LegacyBoard/LegacyListSettings0.vue +++ b/src/components/LegacyBoard/LegacyListSettings0.vue @@ -126,7 +126,7 @@ export default { }, async deleteList() { - this.$store.commit('REMOVE_LIST', this.listIndex); + this.$store.commit('REMOVE_LIST_LEGACY', this.listIndex); await this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists) .catch(() => { @@ -140,7 +140,7 @@ export default { }, async moveList(from, to) { - this.$store.commit('MOVE_LIST', { from, to }); + this.$store.commit('MOVE_LIST_LEGACY', { from, to }); await this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists) .catch(() => { diff --git a/src/components/LegacyBoard/LegacyPlatformsList.vue b/src/components/LegacyBoard/LegacyPlatformsList.vue index 12cfa551..3af5d35d 100644 --- a/src/components/LegacyBoard/LegacyPlatformsList.vue +++ b/src/components/LegacyBoard/LegacyPlatformsList.vue @@ -40,7 +40,7 @@ export default { methods: { changePlatform(platform) { - this.$store.commit('SET_PLATFORM', platform); + this.$store.commit('SET_PLATFORM_LEGACY', platform); this.$router.push({ name: 'legacy-board' }); }, diff --git a/src/components/Lists/ListSettings.vue b/src/components/Lists/ListSettings.vue index 12796020..1c3fff69 100644 --- a/src/components/Lists/ListSettings.vue +++ b/src/components/Lists/ListSettings.vue @@ -126,7 +126,7 @@ export default { }, async deleteList() { - this.$store.commit('REMOVE_LIST', this.listIndex); + this.$store.commit('REMOVE_LIST_LEGACY', this.listIndex); await this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists) .catch(() => { @@ -140,7 +140,7 @@ export default { }, async moveList(from, to) { - this.$store.commit('MOVE_LIST', { from, to }); + this.$store.commit('MOVE_LIST_LEGACY', { from, to }); await this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists) .catch(() => { diff --git a/src/components/Settings/BoardSettings.vue b/src/components/Settings/BoardSettings.vue index b1243603..33c6e9e1 100644 --- a/src/components/Settings/BoardSettings.vue +++ b/src/components/Settings/BoardSettings.vue @@ -92,7 +92,7 @@ export default { }, deleteBoard() { - this.$store.commit('REMOVE_PLATFORM'); + this.$store.commit('REMOVE_PLATFORM_LEGACY'); this.$store.dispatch('SAVE_LIST_NO_MERGE_LEGACY', this.gameLists) .then(() => { diff --git a/src/store/actions.js b/src/store/actions.js index 95d7d57a..caefb469 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -47,7 +47,7 @@ export default { }); }, - LOAD_BOARD({ state }, id) { + LOAD_BOARD({ state, commit }, id) { return new Promise((resolve, reject) => { const db = firebase.firestore(); @@ -57,9 +57,12 @@ export default { .then((docs) => { const board = docs.data(); - return state.user.uid === board.owner - ? resolve(board) - : reject(); + if (state.user.uid !== board.owner) { + return reject(); + } + + commit('SET_BOARD', board); + return resolve(); }) .catch(reject); }); @@ -119,7 +122,7 @@ export default { db.collection('lists').doc(state.user.uid).set(payload, { merge: true }) .then(() => { - commit('SAVE_LIST_LEGACYS', payload); + commit('SAVE_LIST_LEGACY', payload); }); }, @@ -188,7 +191,7 @@ export default { db.collection('lists').doc(state.user.uid).set(payload, { merge: false }) .then(() => { - commit('SAVE_LIST_LEGACYS', payload); + commit('SAVE_LIST_LEGACY', payload); }); }, diff --git a/src/store/mutations.js b/src/store/mutations.js index 3a8b39c1..d8b0b966 100755 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -1,26 +1,14 @@ import Vue from 'vue'; export default { - SET_USER(state, data) { - state.user = { - lastLogin: data.metadata.lastSignInTime, - uid: data.uid, - displayName: data.displayName, - email: data.email, - emailVerified: data.emailVerified, - dateJoined: data.metadata.creationTime, - photoURL: data.photoURL, - }; - }, - - SET_GAME_LISTS(state, lists) { - state.gameLists = lists; - }, - SET_BOARDS(state, boards) { state.boards = boards; }, + SET_BOARD(state, board) { + state.board = board; + }, + SET_GAME_BOARD(state, board) { state.board = board; }, @@ -47,14 +35,85 @@ export default { state.gameModalData = null; }, - SET_SLIDESHOW_OPEN(state, status) { - state.galleryOpen = status; + // + // LEGACY STUFF + // + + ADD_LIST_LEGACY(state, list) { + if (!state.gameLists[state.platform.code]) { + Vue.set(state.gameLists, state.platform.code, []); + } + + state.gameLists[state.platform.code].push(list); }, - SET_WALLPAPER_URL(state, url) { + SET_PLATFORM_LEGACY(state, platform) { + state.platform = platform; + }, + + SAVE_LIST_LEGACY(state, lists) { + state.gameLists = lists; + }, + + REMOVE_GAME_LEGACY(state, { gameId, listId }) { + const currentList = state.gameLists[state.platform.code][listId]; + + currentList.games.splice(currentList.games.indexOf(gameId), 1); + }, + + MOVE_LIST_LEGACY(state, { from, to }) { + const cutOut = state.gameLists[state.platform.code].splice(from, 1)[0]; + + state.gameLists[state.platform.code].splice(to, 0, cutOut); + }, + + REMOVE_LIST_LEGACY(state, index) { + state.gameLists[state.platform.code].splice(index, 1); + }, + + REMOVE_PLATFORM_LEGACY(state) { + Vue.delete(state.gameLists, state.platform.code); + }, + + ADD_GAME_LEGACY(state, { gameId, listId }) { + const currentList = state.gameLists[state.platform.code][listId]; + + currentList.games.push(gameId); + }, + + SET_WALLPAPER_URL_LEGACY(state, url) { state.wallpaperUrl = url; }, + SET_GAME_LISTS_LEGACY(state, lists) { + state.gameLists = lists; + }, + + // + // STUFF THAT REMAINS THE SAME + // + SET_USER(state, data) { + state.user = { + lastLogin: data.metadata.lastSignInTime, + uid: data.uid, + displayName: data.displayName, + email: data.email, + emailVerified: data.emailVerified, + dateJoined: data.metadata.creationTime, + photoURL: data.photoURL, + }; + }, + + CACHE_GAME_DATA(state, data) { + data.forEach((game) => { + Vue.set(state.games, game.id, { ...game }); + }); + }, + + SET_SETTINGS(state, settings) { + state.settings = settings; + }, + UPDATE_TAG(state, { tagName, tagHex, tempTag }) { const updatedTag = { ...state.tags[tempTag.tagName], @@ -75,8 +134,16 @@ export default { state.tags = tags; }, - SET_DRAGGING_STATUS(state, status) { - state.dragging = status; + CLEAR_SESSION(state) { + state.user = null; + state.activeListIndex = null; + state.gameLists = {}; + state.settings = null; + state.platform = null; + state.results = null; + state.games = {}; + state.publicGameData = {}; + state.game = null; }, SET_NOTES(state, notes) { @@ -101,6 +168,10 @@ export default { state.notes[gameId] = note; }, + SET_DRAGGING_STATUS(state, status) { + state.dragging = status; + }, + REMOVE_GAME_NOTE(state, gameId) { if (state.notes[gameId]) { Vue.delete(state.notes, gameId); @@ -115,18 +186,6 @@ export default { state.tags[tagName].games.splice(state.tags[tagName].games.indexOf(gameId), 1); }, - CLEAR_SESSION(state) { - state.user = null; - state.activeListIndex = null; - state.gameLists = {}; - state.settings = null; - state.platform = null; - state.results = null; - state.games = {}; - state.publicGameData = {}; - state.game = null; - }, - SET_SEARCH_RESULTS(state, results) { state.results = results; }, @@ -135,83 +194,7 @@ export default { state.results = []; }, - SET_EDIT_GAME(state, { listId, gameId }) { - state.editGame = gameId; - state.activeListIndex = listId; - }, - - SET_ACTIVE_LIST_INDEX(state, listIndex) { - state.activeListIndex = listIndex; - }, - - CLEAR_ACTIVE_LIST_INDEX(state) { - state.activeListIndex = null; - state.addingList = false; - }, - - SET_PLATFORM(state, platform) { - state.platform = platform; - }, - - SAVE_LIST_LEGACYS(state, lists) { - state.gameLists = lists; - }, - - UPDATE_LIST_TYPE(state, { listIndex, type }) { - state.gameLists[state.platform.code][listIndex].type = type; - }, - - SET_SETTINGS(state, settings) { - state.settings = settings; - }, - UPDATE_SETTING(state, { key, value }) { state.settings[key] = value; }, - - MOVE_LIST(state, { from, to }) { - const cutOut = state.gameLists[state.platform.code].splice(from, 1)[0]; - - state.gameLists[state.platform.code].splice(to, 0, cutOut); - }, - - REMOVE_LIST(state, index) { - state.gameLists[state.platform.code].splice(index, 1); - }, - - REMOVE_PLATFORM(state) { - Vue.delete(state.gameLists, state.platform.code); - }, - - ADD_GAME(state, { gameId, listId }) { - const currentList = state.gameLists[state.platform.code][listId]; - - currentList.games.push(gameId); - }, - - ADD_LIST(state, list) { - if (!state.gameLists[state.platform.code]) { - Vue.set(state.gameLists, state.platform.code, []); - } - - state.gameLists[state.platform.code].push(list); - }, - - REMOVE_GAME(state, { gameId, listId }) { - const currentList = state.gameLists[state.platform.code][listId]; - - currentList.games.splice(currentList.games.indexOf(gameId), 1); - }, - - CACHE_GAME_DATA(state, data) { - data.forEach((game) => { - Vue.set(state.games, game.id, { ...game }); - }); - }, - - SET_PUBLIC_GAME_DATA(state, data) { - data.forEach((game) => { - Vue.set(state.publicGameData, game.id, { ...game }); - }); - }, };