From 2d28475056697167caf0cc1d148bff2074535454 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Thu, 17 Dec 2020 22:48:02 +0100 Subject: [PATCH] feat(vuex): start cdragon/runes module --- .../components/Match/DetailedMatchTeam.vue | 10 +- .../components/Match/Runes/RunesContainer.vue | 44 +++++++++ client/src/plugins/axios.js | 2 +- client/src/store/index.js | 2 + client/src/store/modules/cdragon.js | 36 +++++++ client/src/views/Summoner.vue | 96 ++++++++++--------- 6 files changed, 145 insertions(+), 45 deletions(-) create mode 100644 client/src/components/Match/Runes/RunesContainer.vue create mode 100644 client/src/store/modules/cdragon.js diff --git a/client/src/components/Match/DetailedMatchTeam.vue b/client/src/components/Match/DetailedMatchTeam.vue index a565be5..2c0b538 100644 --- a/client/src/components/Match/DetailedMatchTeam.vue +++ b/client/src/components/Match/DetailedMatchTeam.vue @@ -228,7 +228,7 @@ diff --git a/client/src/components/Match/Runes/RunesContainer.vue b/client/src/components/Match/Runes/RunesContainer.vue new file mode 100644 index 0000000..2bcd2ea --- /dev/null +++ b/client/src/components/Match/Runes/RunesContainer.vue @@ -0,0 +1,44 @@ + + + diff --git a/client/src/plugins/axios.js b/client/src/plugins/axios.js index cdc79c0..4a9b058 100644 --- a/client/src/plugins/axios.js +++ b/client/src/plugins/axios.js @@ -15,7 +15,7 @@ axios.defaults.cancelToken = axiosSource.token // Add season number to data if the route need it axios.interceptors.request.use(function (config) { - if (config.url !== 'summoner/basic' && router.currentRoute.meta.season) { + if (config.method === 'post' && config.url !== 'summoner/basic' && router.currentRoute.meta.season) { config.data.season = store.state.summoner.basic.currentSeason } return config diff --git a/client/src/store/index.js b/client/src/store/index.js index e7aa39d..0a00df8 100644 --- a/client/src/store/index.js +++ b/client/src/store/index.js @@ -1,5 +1,6 @@ import Vue from 'vue' import Vuex from 'vuex' +import * as cdragon from '@/store/modules/cdragon' import * as detailedMatch from '@/store/modules/detailedMatch' import * as notification from '@/store/modules/notification' import * as settings from '@/store/modules/settings' @@ -11,6 +12,7 @@ const debug = process.env.NODE_ENV !== 'production' export default new Vuex.Store({ modules: { + cdragon, detailedMatch, notification, settings, diff --git a/client/src/store/modules/cdragon.js b/client/src/store/modules/cdragon.js new file mode 100644 index 0000000..a8abd7d --- /dev/null +++ b/client/src/store/modules/cdragon.js @@ -0,0 +1,36 @@ +import { axios } from '@/plugins/axios' + +export const namespaced = true + +export const state = { + runes: null, + runesOpen: false, + selectedRunes: {}, +} + +export const mutations = { + DISPLAY_HIDE_RUNES(state, selectedRunes) { + state.runesOpen = !state.runesOpen + state.selectedRunes = selectedRunes + }, + SET_RUNES(state, runes) { + state.runes = runes + }, +} + +export const actions = { + displayOrHideRunes({ commit }, selectedRunes) { + commit('DISPLAY_HIDE_RUNES', selectedRunes) + }, + async getRunes({ commit, getters }) { + if (getters.runesLoaded) { return } + + const { data } = await axios.get('cdragon/runes').catch((e) => { console.log(e) }) + console.log(data) + commit('SET_RUNES', data) + }, +} + +export const getters = { + runesLoaded: state => state.runes, +} diff --git a/client/src/views/Summoner.vue b/client/src/views/Summoner.vue index b53da32..2aae3e0 100644 --- a/client/src/views/Summoner.vue +++ b/client/src/views/Summoner.vue @@ -1,51 +1,54 @@ @@ -56,6 +59,7 @@ import LiveMatch from '@/components/Match/LiveMatch.vue' import LoadingButton from '@/components/Form/LoadingButton.vue' import Match from '@/components/Match/Match.vue' import OverviewLoader from '@/components/Summoner/Overview/OverviewLoader.vue' +import RunesContainer from '@/components/Match/Runes/RunesContainer.vue' import SummonerChampions from '@/components/Summoner/Overview/SummonerChampions.vue' import SummonerMates from '@/components/Summoner/Overview/SummonerMates.vue' import SummonerStats from '@/components/Summoner/Overview/SummonerStats.vue' @@ -67,6 +71,7 @@ export default { LoadingButton, Match, OverviewLoader, + RunesContainer, SummonerChampions, SummonerMates, SummonerStats, @@ -76,7 +81,9 @@ export default { computed: { ...mapState({ current: state => state.summoner.live.match, - overview: state => state.summoner.overview + overview: state => state.summoner.overview, + runesOpen: state => state.cdragon.runesOpen, + selectedRunes: state => state.cdragon.selectedRunes }), ...mapGetters('summoner', ['matchesLoading', 'moreMatchesToFetch', 'overviewLoaded', 'summonerFound']) }, @@ -92,6 +99,8 @@ export default { created() { this.fetchData() + + this.getRunes() }, methods: { @@ -104,6 +113,7 @@ export default { this.sliceOverviewMatches(10) } }, + ...mapActions('cdragon', ['getRunes']), ...mapActions('summoner', ['moreMatches', 'overviewRequest', 'sliceOverviewMatches']), },