gamebrary/src/store/mutations.js

258 lines
6.8 KiB
JavaScript
Raw Normal View History

import Vue from 'vue';
2018-10-19 05:15:28 +00:00
export default {
SET_USER(state, data) {
state.isTouchDevice = ('ontouchstart' in window);
state.user = {
2019-09-24 17:03:36 +00:00
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;
},
2019-08-01 17:26:59 +00:00
SET_SLIDESHOW_OPEN(state, status) {
state.galleryOpen = status;
},
2019-04-09 04:17:26 +00:00
SET_WALLPAPER_URL(state, url) {
state.wallpaperUrl = url;
},
2019-07-25 22:36:35 +00:00
UPDATE_TAG(state, { tagName, tagHex, tempTag }) {
const updatedTag = {
...state.tags[tempTag.tagName],
hex: tagHex,
};
const renaming = tagName !== tempTag.tagName;
if (renaming) {
Vue.set(state.tags, tagName, updatedTag);
Vue.delete(state.tags, tempTag.tagName);
} else {
state.tags[tempTag.tagName] = updatedTag;
}
},
2019-02-08 05:46:29 +00:00
SET_RELEASES(state, releases) {
state.releases = releases;
},
2019-02-08 06:15:16 +00:00
SET_TAGS(state, tags) {
state.tags = tags;
},
2019-04-19 20:27:45 +00:00
SET_NOTES(state, notes) {
state.notes = notes;
},
2019-02-08 06:15:16 +00:00
ADD_GAME_TAG(state, { tagName, gameId }) {
state.tags[tagName].games.push(gameId);
},
REMOVE_GAME_TAG(state, { tagName, gameId }) {
state.tags[tagName].games.splice(state.tags[tagName].games.indexOf(gameId), 1);
},
CLEAR_SESSION(state) {
state.user = null;
2019-04-03 23:21:27 +00:00
state.activeListIndex = null;
2018-11-27 23:59:19 +00:00
state.gameLists = {};
2018-10-27 05:27:43 +00:00
state.settings = null;
2018-11-25 21:18:34 +00:00
state.platform = null;
2018-10-27 05:27:43 +00:00
state.results = null;
2018-11-25 21:18:34 +00:00
state.games = {};
state.publicGameData = {};
2018-10-27 05:27:43 +00:00
state.game = null;
2018-10-19 05:15:28 +00:00
},
SET_SEARCH_RESULTS(state, results) {
state.results = results;
},
CLEAR_SEARCH_RESULTS(state) {
state.results = [];
},
2018-11-17 22:20:54 +00:00
SET_ACTIVE_GAME(state, [game]) {
state.game = game;
},
CLEAR_ACTIVE_GAME(state) {
state.game = null;
2018-10-19 05:15:28 +00:00
},
SET_EDIT_GAME(state, { listId, gameId }) {
state.editGame = gameId;
2019-04-03 23:21:27 +00:00
state.activeListIndex = listId;
2018-10-19 05:15:28 +00:00
},
2019-04-03 23:21:27 +00:00
SET_SEARCH_ACTIVE(state, status) {
state.searchActive = status;
2018-10-19 05:15:28 +00:00
},
2019-04-05 22:46:56 +00:00
SET_ADDING_LIST_STATUS(state, status) {
state.addingList = status;
},
2019-04-03 23:21:27 +00:00
SET_ACTIVE_LIST_INDEX(state, listIndex) {
state.activeListIndex = listIndex;
},
CLEAR_ACTIVE_LIST_INDEX(state) {
state.activeListIndex = null;
state.searchActive = null;
2019-04-18 20:31:15 +00:00
state.addingList = false;
2019-02-05 07:32:08 +00:00
},
2018-10-19 05:15:28 +00:00
SET_PLATFORM(state, platform) {
state.platform = platform;
},
2018-12-21 22:35:12 +00:00
SORT_LIST_ALPHABETICALLY(state, listIndex) {
const games = state.gameLists[state.platform.code][listIndex].games;
2018-10-19 05:15:28 +00:00
games.sort((a, b) => {
2019-03-29 20:43:12 +00:00
const gameA = state.games[a] && state.games[a].name
? state.games[a].name.toUpperCase()
: '';
const gameB = state.games[b] && state.games[b].name
? state.games[b].name.toUpperCase()
: '';
2018-10-19 05:15:28 +00:00
if (gameA < gameB) {
return -1;
}
return gameA > gameB ? 1 : 0;
});
},
2019-05-23 20:49:09 +00:00
SORT_LIST_BY_RELEASE_DATE(state, listIndex) {
const games = state.gameLists[state.platform.code][listIndex].games;
games.sort((a, b) => {
const gameA = state.games[a] && state.games[a].release_dates
&& state.games[a].release_dates.length > 0
? state.games[a].release_dates.find(releaseDate =>
releaseDate.platform === state.platform.id).date : 0;
const gameB = state.games[b] && state.games[b].release_dates
&& state.games[b].release_dates.length > 0
? state.games[b].release_dates.find(releaseDate =>
releaseDate.platform === state.platform.id).date : 0;
if (gameA > gameB) {
return -1;
}
return gameA < gameB ? 1 : 0;
});
},
2018-12-21 22:35:12 +00:00
SORT_LIST_BY_RATING(state, listIndex) {
const games = state.gameLists[state.platform.code][listIndex].games;
games.sort((a, b) => {
2019-03-29 20:40:24 +00:00
const gameA = state.games[a] && state.games[a].rating
? state.games[a].rating
: 0;
const gameB = state.games[b] && state.games[b].rating
? state.games[b].rating
: 0;
2018-12-21 22:35:12 +00:00
if (gameA > gameB) {
return -1;
}
return gameA < gameB ? 1 : 0;
});
},
2018-10-19 05:15:28 +00:00
UPDATE_LIST_NAME(state, { listIndex, listName }) {
state.gameLists[state.platform.code][listIndex].name = listName;
2018-10-19 05:15:28 +00:00
},
2019-04-03 23:21:27 +00:00
UPDATE_LIST_VIEW(state, { listIndex, view }) {
state.gameLists[state.platform.code][listIndex].view = view;
},
2019-08-09 04:18:06 +00:00
UPDATE_LIST_TYPE(state, { listIndex, type }) {
state.gameLists[state.platform.code][listIndex].type = type;
},
UPDATE_LIST_SORT(state, { listIndex, sortOrder }) {
state.gameLists[state.platform.code][listIndex].sortOrder = sortOrder;
},
UPDATE_LIST_COVERS_SIZE(state, { listIndex, size }) {
state.gameLists[state.platform.code][listIndex].coversSize = size;
},
2018-10-19 05:15:28 +00:00
SET_SETTINGS(state, settings) {
state.settings = settings;
2018-10-19 05:15:28 +00:00
},
2018-11-25 21:18:34 +00:00
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);
},
2018-10-19 05:15:28 +00:00
REMOVE_LIST(state, index) {
state.gameLists[state.platform.code].splice(index, 1);
2018-10-19 05:15:28 +00:00
},
REMOVE_PLATFORM(state) {
Vue.delete(state.gameLists, state.platform.code);
},
2018-10-19 05:15:28 +00:00
ADD_GAME(state, { gameId, listId }) {
const currentList = state.gameLists[state.platform.code][listId];
currentList.games.push(gameId);
2018-10-19 05:15:28 +00:00
},
ADD_LIST(state, { listName, listType }) {
2018-10-19 05:15:28 +00:00
const newList = {
games: [],
name: listName,
type: listType,
2018-10-19 05:15:28 +00:00
};
if (!state.gameLists[state.platform.code]) {
Vue.set(state.gameLists, state.platform.code, []);
}
state.gameLists[state.platform.code].push(newList);
2018-10-19 05:15:28 +00:00
},
REMOVE_GAME(state, { gameId, listId }) {
const currentList = state.gameLists[state.platform.code][listId];
currentList.games.splice(currentList.games.indexOf(gameId), 1);
2018-10-19 05:15:28 +00:00
},
CACHE_GAME_DATA(state, data) {
data.forEach((game) => {
2018-10-27 05:27:27 +00:00
Vue.set(state.games, game.id, { ...game });
2018-10-19 05:15:28 +00:00
});
},
2018-11-21 02:43:10 +00:00
SET_PUBLIC_GAME_DATA(state, data) {
data.forEach((game) => {
Vue.set(state.publicGameData, game.id, { ...game });
});
},
2018-10-19 05:15:28 +00:00
};