From d619ac97968dab4da570b8dbba4b1cffebba6fea Mon Sep 17 00:00:00 2001
From: Gamebrary
Date: Thu, 11 Aug 2022 23:34:40 -0700
Subject: [PATCH] Refactor tags
---
public/index.html | 2 +-
src/App.vue | 4 -
src/components/GameCards/GameCardCompact.vue | 26 ++--
src/components/GameCards/GameCardDefault.vue | 6 +-
src/components/GameCards/GameCardGrid.vue | 5 +-
src/components/GameCards/GameCardText.vue | 5 +-
src/components/Tags/TagsList.vue | 32 ++---
src/constants.js | 2 +-
src/mixins/gameCardMixin.js | 19 +--
src/pages/CreateTagPage.vue | 121 +++++++------------
src/pages/EditTagPage.vue | 47 ++-----
src/pages/GamePage.vue | 10 +-
src/pages/GameTagsPage.vue | 97 ++++++---------
src/pages/TagsPage.vue | 5 +-
src/store/actions.js | 17 ++-
src/store/getters.js | 13 --
src/store/mutations.js | 44 ++++---
17 files changed, 181 insertions(+), 274 deletions(-)
diff --git a/public/index.html b/public/index.html
index 71cc8d74..9ec60d6b 100644
--- a/public/index.html
+++ b/public/index.html
@@ -7,7 +7,7 @@
-
+
diff --git a/src/App.vue b/src/App.vue
index 3348125d..e1386f48 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -100,10 +100,6 @@ export default {
isGamePage() {
return this.$route.name === 'game';
},
-
- isBoard() {
- return ['public.board', 'board'].includes(this.$route.name);
- },
},
watch: {
diff --git a/src/components/GameCards/GameCardCompact.vue b/src/components/GameCards/GameCardCompact.vue
index 1a92031c..59e835f3 100644
--- a/src/components/GameCards/GameCardCompact.vue
+++ b/src/components/GameCards/GameCardCompact.vue
@@ -37,19 +37,19 @@
height="6px"
/>
-
-
- {{ name }}
-
-
+
+
+
diff --git a/src/components/GameCards/GameCardDefault.vue b/src/components/GameCards/GameCardDefault.vue
index e541615d..ae6349cc 100644
--- a/src/components/GameCards/GameCardDefault.vue
+++ b/src/components/GameCards/GameCardDefault.vue
@@ -42,14 +42,14 @@
{{ gameProgress }}%
-
+
{{ name }}
diff --git a/src/components/GameCards/GameCardGrid.vue b/src/components/GameCards/GameCardGrid.vue
index 2abd1697..35e21831 100644
--- a/src/components/GameCards/GameCardGrid.vue
+++ b/src/components/GameCards/GameCardGrid.vue
@@ -21,7 +21,8 @@
height="6px"
/>
-
+
+
diff --git a/src/components/GameCards/GameCardText.vue b/src/components/GameCards/GameCardText.vue
index 13401d74..0dcefa22 100644
--- a/src/components/GameCards/GameCardText.vue
+++ b/src/components/GameCards/GameCardText.vue
@@ -23,7 +23,8 @@
height="6px"
/>
-
+
+
diff --git a/src/components/Tags/TagsList.vue b/src/components/Tags/TagsList.vue
index ddf16b40..0cab58de 100644
--- a/src/components/Tags/TagsList.vue
+++ b/src/components/Tags/TagsList.vue
@@ -1,22 +1,16 @@
-
-
+
-
- {{ name }}
-
-
+ {{ name }}
+
@@ -43,13 +37,5 @@ export default {
this.loading = false;
},
-
- methods: {
- openGame(gameId) {
- const { id, slug } = this.games[gameId];
-
- this.$router.push({ name: 'game.tags', params: { id, slug } })
- },
- },
};
diff --git a/src/constants.js b/src/constants.js
index 99f58248..d361aea6 100644
--- a/src/constants.js
+++ b/src/constants.js
@@ -74,7 +74,7 @@ export const GENRE_ICONS = {
export const KEYBOARD_SHORTCUTS = {
'MODAL_keyboard-shortcuts': ['shift', '?'],
'MODAL_create-board': ['shift', 'c'],
- MODAL_devTools: ['shift', 'd'],
+ // MODAL_devTools: ['shift', 'd'],
ROUTE_boards: ['shift', 'b'],
ROUTE_tags: ['shift', 't'],
ROUTE_notes: ['shift', 'n'],
diff --git a/src/mixins/gameCardMixin.js b/src/mixins/gameCardMixin.js
index f2d8cfef..c2ceb332 100644
--- a/src/mixins/gameCardMixin.js
+++ b/src/mixins/gameCardMixin.js
@@ -17,25 +17,10 @@ export default {
return this.gameProgress && Number(this.gameProgress) === 100;
},
- gameTags() {
- const tagsArray = Object.entries(this.tags);
- const filteredTags = tagsArray.filter(([key, value]) => {
- return value.games.includes(this.gameId);
- });
-
- const filteredTagsObject = Object.fromEntries(filteredTags);
-
- return filteredTagsObject;
- },
-
showGameProgress() {
return this.gameProgress > 0;
},
- showGameTags() {
- return this.list?.settings?.showGameTags && this.gameTags;
- },
-
showReleaseDates() {
return this.list?.settings?.showReleaseDates;
},
@@ -48,6 +33,10 @@ export default {
: 0;
},
+ tagsApplied() {
+ return this.tags?.filter((tag) => tag?.games?.includes(this.game?.id))
+ },
+
gameNotes() {
const { settings } = this.list;
diff --git a/src/pages/CreateTagPage.vue b/src/pages/CreateTagPage.vue
index 62832273..4442ac13 100644
--- a/src/pages/CreateTagPage.vue
+++ b/src/pages/CreateTagPage.vue
@@ -4,112 +4,85 @@
Create tag
-
diff --git a/src/pages/EditTagPage.vue b/src/pages/EditTagPage.vue
index 6cfb458f..04644574 100644
--- a/src/pages/EditTagPage.vue
+++ b/src/pages/EditTagPage.vue
@@ -34,14 +34,6 @@
ref="form"
@submit="saveTag"
>
-
- You already have a tag named {{ tag.name }}
-
-
Background color
-
Text color
@@ -79,7 +70,7 @@
size="sm"
class="mr-2 mb-2 field"
variant="outline-light"
- :style="`background-color: ${tag.hex}; color: ${tag.tagTextColor}`"
+ :style="`background-color: ${tag.bgColor}; color: ${tag.textColor}`"
>
{{ tag.name }}
@@ -88,6 +79,11 @@
Games tagged
+
+ No games tagged
+
+
+
@@ -122,7 +118,6 @@ export default {
return {
tag: {},
loading: true,
- originalTagName: '',
localTags: {},
saving: false,
}
@@ -135,18 +130,6 @@ export default {
computed: {
...mapState(['tags', 'games']),
- tagNames() {
- const sanitizedNames = this.tags?.map(({ name }) => name.toLowerCase());
-
- return sanitizedNames.length > 0
- ? sanitizedNames.filter(name => name?.toLowerCase() !== this.originalTagName?.toLowerCase())
- : [];
- },
-
- isEditedNameDuplicate() {
- return this.tagNames?.includes(this.tag?.name?.toLowerCase());
- },
-
tagIndex() {
return this.$route?.params?.id;
},
@@ -172,7 +155,6 @@ export default {
const { tags, tagIndex } = this;
this.tag = JSON.parse(JSON.stringify(tags[tagIndex]));
- this.originalTagName = JSON.parse(JSON.stringify(this.tag.name));
this.loading = false;
},
@@ -194,20 +176,15 @@ export default {
},
deleteTag(tagName) {
- this.$delete(this.localTags, tagName);
- this.saveTags(true);
- },
-
- removeTag(tagName) {
- this.$store.commit('REMOVE_GAME_TAG', { tagName, gameId: this.gameId });
- this.saveTags();
+ // TODO: call mutation to remove tag and save tags
+ // this.saveTags(true);
},
async saveTag(e) {
e.preventDefault();
if (this.$refs.form.checkValidity()) {
- const { tag, tags, originalTagName } = this;
+ const { tag, tags } = this;
tags[this.tagIndex] = tag;
diff --git a/src/pages/GamePage.vue b/src/pages/GamePage.vue
index 7486bb7d..dd539123 100644
--- a/src/pages/GamePage.vue
+++ b/src/pages/GamePage.vue
@@ -96,14 +96,12 @@
{{ name }}
@@ -335,6 +333,10 @@ export default {
},
+ tagsApplied() {
+ return this.tags?.filter((tag) => tag?.games?.includes(this.game?.id))
+ },
+
legalNotice() {
return this.game?.steam?.legal_notice;
},
diff --git a/src/pages/GameTagsPage.vue b/src/pages/GameTagsPage.vue
index b23ceb9f..0fee08f4 100644
--- a/src/pages/GameTagsPage.vue
+++ b/src/pages/GameTagsPage.vue
@@ -51,22 +51,20 @@
Tags applied to {{ game.name }}
-
+
No tags applied
-
+
{{ name }}
@@ -76,19 +74,19 @@
Tags available
- {{ tags }}
-
+
@@ -131,36 +129,25 @@ export default {
return Object.keys(this.tags).length === 0;
},
- tagsSelected() {
- return this.tags?.filter(({ games }) => {
- return games?.includes(this.game?.id);
- })
+ formattedTags() {
+ return this.tags.map((tag) => ({
+ ...tag,
+ selected: tag.games.includes(Number(this.$route.params.id)),
+ }));
},
- tagsAvailable() {
- return Object.entries(this.tags).map((t) => {
- const [name, tag] = t;
-
- return { name: name, ...tag };
- })
- .filter(({ games }) => {
- return !games.includes(this.game.id);
- })
+ noneSelected() {
+ return !this.formattedTags.some(({ selected }) => Boolean(selected));
},
},
mounted() {
- if (this.game?.id !== this.$route.params.id) {
- this.loadGame();
- } else {
- this.loading = false;
- }
+ this.load();
},
methods: {
- async loadGame() {
+ async load() {
this.loading = true;
- this.$store.commit('CLEAR_GAME');
await this.$store.dispatch('LOAD_GAME', this.$route.params.id);
await this.$store.dispatch('LOAD_TAGS')
@@ -172,36 +159,28 @@ export default {
},
async addTag(index) {
- console.log('add this tag');
- // TODO: use commit instead?
- // const gameId = this.game.id;
- //
- // if (!gameId) return;
- //
- // const tags = JSON.parse(JSON.stringify(this.tags)) ;
- //
- // tags[index].games.push(gameId)
- //
- // console.log(`game id ${gameId} should be included`, tags[index].games);
+ this.$store.commit('APPLY_TAG_TO_GAME', index);
+ this.saving = true;
- // this.saving = true;
+ await this.$store.dispatch('SAVE_GAME_TAGS')
+ .catch(() => {
+ this.saving = false;
+ });
- // await this.$store.dispatch('SAVE_TAGS', tags)
- // .catch((e) => {
- // console.log(e);
- // });
-
- // this.saving = false;
-
- // this.$store.commit('ADD_GAME_TAG', { tagName, gameId });
- // await this.saveTags();
+ this.saving = false;
},
- async removeTag(tagName) {
- const gameId = this.game.id;
+ async removeTag(index) {
+ this.$store.commit('REMOVE_GAME_TAG', index);
- // this.$store.commit('REMOVE_GAME_TAG', { tagName, gameId });
- // await this.saveTags();
+ this.saving = true;
+
+ await this.$store.dispatch('SAVE_GAME_TAGS')
+ .catch(() => {
+ this.saving = false;
+ });
+
+ this.saving = false;
},
manageTags() {
diff --git a/src/pages/TagsPage.vue b/src/pages/TagsPage.vue
index 24087c4c..f8460c7f 100644
--- a/src/pages/TagsPage.vue
+++ b/src/pages/TagsPage.vue
@@ -7,6 +7,7 @@
-
-
-
+
diff --git a/src/store/actions.js b/src/store/actions.js
index d7816158..11e303b8 100644
--- a/src/store/actions.js
+++ b/src/store/actions.js
@@ -581,6 +581,18 @@ export default {
});
},
+ SAVE_GAME_TAGS({ state }) {
+ const db = firestore();
+
+ return new Promise((resolve, reject) => {
+ db.collection('tags')
+ .doc(state.user.uid)
+ .set({ tags: state.tags }, { merge: false })
+ .then(() => resolve())
+ .catch(reject);
+ });
+ },
+
GET_TWITCH_TOKEN({ commit }) {
const db = firestore();
@@ -726,14 +738,13 @@ export default {
const { tags } = doc.data();
if (typeof tags === 'object') {
- console.warn('Legacy tag detected');
-
+ // console.warn('Legacy tag detected');
const formattedTags = Object.entries(tags).map(([ ,tag]) => ({ ...tag }));
commit('SET_TAGS', formattedTags);
resolve(formattedTags);
} else {
- console.log('is type', typeof tags);
+ // console.log('is type', typeof tags);
}
});
});
diff --git a/src/store/getters.js b/src/store/getters.js
index 11ebdc00..23c73d71 100644
--- a/src/store/getters.js
+++ b/src/store/getters.js
@@ -9,19 +9,6 @@ export default {
return board?.owner === user?.uid;
},
- gameTags: ({ tags, game }) => {
- if (!game?.id) return [];
- // TODO: refactor architecture, don't use tag name as key
- const tagsArray = Object.entries(tags);
- const filteredTags = tagsArray.filter(([key, value]) => {
- return value.games.includes(game.id);
- });
-
- const filteredTagsObject = Object.fromEntries(filteredTags);
-
- return filteredTagsObject;
- },
-
// Arabic is the only ltr language supported at the moment
isRTL: ({ settings }) => settings && settings.language !== 'ar',
diff --git a/src/store/mutations.js b/src/store/mutations.js
index cec1d5a3..fcc9400c 100644
--- a/src/store/mutations.js
+++ b/src/store/mutations.js
@@ -175,21 +175,21 @@ export default {
state.settings = settings;
},
- 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;
- }
- },
+ // 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;
+ // }
+ // },
SET_TAGS(state, tags) {
state.tags = tags;
@@ -247,12 +247,18 @@ export default {
}
},
- ADD_GAME_TAG(state, { tagName, gameId }) {
- state.tags[tagName].games.push(gameId);
+ APPLY_TAG_TO_GAME(state, tagIndex) {
+ state.tags[tagIndex].games.push(state.game.id);
},
- REMOVE_GAME_TAG(state, { tagName, gameId }) {
- state.tags[tagName].games.splice(state.tags[tagName].games.indexOf(gameId), 1);
+ CREATE_TAG(state, tag) {
+ state.tags.push(tag);
+ },
+
+ REMOVE_GAME_TAG(state, tagIndex) {
+ const gameIndex = state.tags[tagIndex].games.indexOf(state.game.id);
+
+ state.tags[tagIndex].games.splice(gameIndex, 1);
},
SET_SEARCH_RESULTS(state, results) {