rename mutations as well

This commit is contained in:
Gamebrary 2020-08-18 15:01:16 -07:00
parent 1617fbc71a
commit 07de00ce5b
15 changed files with 134 additions and 137 deletions

View file

@ -133,7 +133,7 @@ export default {
this.loadWallpaper(); this.loadWallpaper();
} }
} else { } else {
this.$store.commit('SET_WALLPAPER_URL', ''); this.$store.commit('SET_WALLPAPER_URL_LEGACY', '');
} }
}, },
}, },
@ -181,10 +181,10 @@ export default {
loadWallpaper() { loadWallpaper() {
const wallpaperRef = this.customWallpaper; const wallpaperRef = this.customWallpaper;
this.$store.commit('SET_WALLPAPER_URL', ''); this.$store.commit('SET_WALLPAPER_URL_LEGACY', '');
storage.child(wallpaperRef).getDownloadURL().then((url) => { 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) => { .onSnapshot((doc) => {
if (doc.exists) { if (doc.exists) {
const gameLists = doc.data(); 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) => { .then((doc) => {
if (doc.exists) { if (doc.exists) {
const data = doc.data(); const data = doc.data();
this.$store.commit('SET_GAME_LISTS', data); this.$store.commit('SET_GAME_LISTS_LEGACY', data);
} else { } else {
this.initList(); this.initList();
} }

View file

@ -124,7 +124,7 @@ export default {
this.saving = true; this.saving = true;
this.$store.dispatch('ADD_LIST', list) this.$store.dispatch('ADD_LIST_LEGACY', list)
.then(() => { .then(() => {
this.$bvToast.toast('List added', { this.$bvToast.toast('List added', {
variant: 'success', variant: 'success',

View file

@ -516,7 +516,7 @@ export default {
}; };
// this.$emit('added'); // this.$emit('added');
this.$store.commit('ADD_GAME', data); this.$store.commit('ADD_GAME_LEGACY', data);
this.$ga.event({ this.$ga.event({
eventCategory: 'game', eventCategory: 'game',
@ -542,7 +542,7 @@ export default {
gameId: this.game.id, gameId: this.game.id,
}; };
this.$store.commit('REMOVE_GAME', data); this.$store.commit('REMOVE_GAME_LEGACY', data);
this.$store this.$store
.dispatch('SAVE_LIST_LEGACY', this.gameLists) .dispatch('SAVE_LIST_LEGACY', this.gameLists)
@ -574,6 +574,12 @@ export default {
this.$bvToast.toast('Error loading game', { title: 'Error', variant: 'error' }); 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 = {
...this.game, ...this.game,
...game, ...game,

View file

@ -104,7 +104,7 @@ export default {
}; };
this.$emit('added'); this.$emit('added');
this.$store.commit('ADD_GAME', data); this.$store.commit('ADD_GAME_LEGACY', data);
this.$ga.event({ this.$ga.event({
eventCategory: 'game', eventCategory: 'game',

View file

@ -124,7 +124,7 @@ export default {
this.saving = true; this.saving = true;
this.$store.commit('ADD_LIST', list); this.$store.commit('ADD_LIST_LEGACY', list);
this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists) this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists)
.then(() => { .then(() => {

View file

@ -92,7 +92,7 @@ export default {
}, },
deleteBoard() { deleteBoard() {
this.$store.commit('REMOVE_PLATFORM'); this.$store.commit('REMOVE_PLATFORM_LEGACY');
this.$store.dispatch('SAVE_LIST_NO_MERGE_LEGACY', this.gameLists) this.$store.dispatch('SAVE_LIST_NO_MERGE_LEGACY', this.gameLists)
.then(() => { .then(() => {

View file

@ -104,7 +104,7 @@ export default {
}; };
this.$emit('added'); this.$emit('added');
this.$store.commit('ADD_GAME', data); this.$store.commit('ADD_GAME_LEGACY', data);
this.$ga.event({ this.$ga.event({
eventCategory: 'game', eventCategory: 'game',

View file

@ -516,7 +516,7 @@ export default {
}; };
// this.$emit('added'); // this.$emit('added');
this.$store.commit('ADD_GAME', data); this.$store.commit('ADD_GAME_LEGACY', data);
this.$ga.event({ this.$ga.event({
eventCategory: 'game', eventCategory: 'game',
@ -542,7 +542,7 @@ export default {
gameId: this.game.id, gameId: this.game.id,
}; };
this.$store.commit('REMOVE_GAME', data); this.$store.commit('REMOVE_GAME_LEGACY', data);
this.$store this.$store
.dispatch('SAVE_LIST_LEGACY', this.gameLists) .dispatch('SAVE_LIST_LEGACY', this.gameLists)
@ -574,6 +574,11 @@ export default {
this.$bvToast.toast('Error loading game', { title: 'Error', variant: 'error' }); 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 = {
...this.game, ...this.game,
...game, ...game,

View file

@ -126,7 +126,7 @@ export default {
}, },
async deleteList() { 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) await this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists)
.catch(() => { .catch(() => {
@ -140,7 +140,7 @@ export default {
}, },
async moveList(from, to) { 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) await this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists)
.catch(() => { .catch(() => {

View file

@ -126,7 +126,7 @@ export default {
}, },
async deleteList() { 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) await this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists)
.catch(() => { .catch(() => {
@ -140,7 +140,7 @@ export default {
}, },
async moveList(from, to) { 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) await this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists)
.catch(() => { .catch(() => {

View file

@ -40,7 +40,7 @@ export default {
methods: { methods: {
changePlatform(platform) { changePlatform(platform) {
this.$store.commit('SET_PLATFORM', platform); this.$store.commit('SET_PLATFORM_LEGACY', platform);
this.$router.push({ name: 'legacy-board' }); this.$router.push({ name: 'legacy-board' });
}, },

View file

@ -126,7 +126,7 @@ export default {
}, },
async deleteList() { 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) await this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists)
.catch(() => { .catch(() => {
@ -140,7 +140,7 @@ export default {
}, },
async moveList(from, to) { 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) await this.$store.dispatch('SAVE_LIST_LEGACY', this.gameLists)
.catch(() => { .catch(() => {

View file

@ -92,7 +92,7 @@ export default {
}, },
deleteBoard() { deleteBoard() {
this.$store.commit('REMOVE_PLATFORM'); this.$store.commit('REMOVE_PLATFORM_LEGACY');
this.$store.dispatch('SAVE_LIST_NO_MERGE_LEGACY', this.gameLists) this.$store.dispatch('SAVE_LIST_NO_MERGE_LEGACY', this.gameLists)
.then(() => { .then(() => {

View file

@ -47,7 +47,7 @@ export default {
}); });
}, },
LOAD_BOARD({ state }, id) { LOAD_BOARD({ state, commit }, id) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const db = firebase.firestore(); const db = firebase.firestore();
@ -57,9 +57,12 @@ export default {
.then((docs) => { .then((docs) => {
const board = docs.data(); const board = docs.data();
return state.user.uid === board.owner if (state.user.uid !== board.owner) {
? resolve(board) return reject();
: reject(); }
commit('SET_BOARD', board);
return resolve();
}) })
.catch(reject); .catch(reject);
}); });
@ -119,7 +122,7 @@ export default {
db.collection('lists').doc(state.user.uid).set(payload, { merge: true }) db.collection('lists').doc(state.user.uid).set(payload, { merge: true })
.then(() => { .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 }) db.collection('lists').doc(state.user.uid).set(payload, { merge: false })
.then(() => { .then(() => {
commit('SAVE_LIST_LEGACYS', payload); commit('SAVE_LIST_LEGACY', payload);
}); });
}, },

View file

@ -1,26 +1,14 @@
import Vue from 'vue'; import Vue from 'vue';
export default { 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) { SET_BOARDS(state, boards) {
state.boards = boards; state.boards = boards;
}, },
SET_BOARD(state, board) {
state.board = board;
},
SET_GAME_BOARD(state, board) { SET_GAME_BOARD(state, board) {
state.board = board; state.board = board;
}, },
@ -47,14 +35,85 @@ export default {
state.gameModalData = null; 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; 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 }) { UPDATE_TAG(state, { tagName, tagHex, tempTag }) {
const updatedTag = { const updatedTag = {
...state.tags[tempTag.tagName], ...state.tags[tempTag.tagName],
@ -75,8 +134,16 @@ export default {
state.tags = tags; state.tags = tags;
}, },
SET_DRAGGING_STATUS(state, status) { CLEAR_SESSION(state) {
state.dragging = status; 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) { SET_NOTES(state, notes) {
@ -101,6 +168,10 @@ export default {
state.notes[gameId] = note; state.notes[gameId] = note;
}, },
SET_DRAGGING_STATUS(state, status) {
state.dragging = status;
},
REMOVE_GAME_NOTE(state, gameId) { REMOVE_GAME_NOTE(state, gameId) {
if (state.notes[gameId]) { if (state.notes[gameId]) {
Vue.delete(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); 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) { SET_SEARCH_RESULTS(state, results) {
state.results = results; state.results = results;
}, },
@ -135,83 +194,7 @@ export default {
state.results = []; 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 }) { UPDATE_SETTING(state, { key, value }) {
state.settings[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 });
});
},
}; };