diff --git a/client/src/store/modules/settings.js b/client/src/store/modules/settings.js
index 2409b91..2d6a1d8 100644
--- a/client/src/store/modules/settings.js
+++ b/client/src/store/modules/settings.js
@@ -1,21 +1,80 @@
export const namespaced = true
export const state = {
+ favorites: [],
percent: false,
+ recentSearches: [],
region: 'euw',
}
export const mutations = {
+ ADD_FAVORITE(state, summoner) {
+ state.favorites.push(summoner)
+ },
+ ADD_SEARCH(state, summoner) {
+ let searches = state.recentSearches
+
+ const alreadySearch = searches.find(s => s.name === summoner.name)
+ if (alreadySearch) {
+ alreadySearch.date = Date.now()
+ searches.sort((a, b) => b.date - a.date)
+ return
+ }
+
+ if (searches.length >= 6) {
+ searches.pop()
+ }
+
+ summoner.date = Date.now()
+ searches.unshift(summoner)
+ },
+ REMOVE_FAVORITE(state, summonerName) {
+ state.favorites = state.favorites.filter(s => s.name !== summonerName)
+ },
+ REMOVE_SEARCH(state, summonerName) {
+ state.recentSearches = state.recentSearches.filter(s => s.name !== summonerName)
+ },
+ UPDATE_FAVORITES(state, favorites) {
+ state.favorites = favorites
+ },
UPDATE_PERCENT(state, percent) {
state.percent = percent
},
+ UPDATE_RECENT_SEARCHES(state, recentSearches) {
+ state.recentSearches = recentSearches
+ },
UPDATE_REGION(state, region) {
state.region = region
- }
+ },
}
export const actions = {
- async updatePercent({ commit }, percent) {
+ addRecentSearch({ commit, dispatch, state }, summoner) {
+ commit('ADD_SEARCH', summoner)
+ dispatch('updateSettings', { name: 'recent_searches', value: state.recentSearches, isJson: true })
+ },
+ removeRecentSearch({ commit, dispatch }, summoner) {
+ commit('REMOVE_SEARCH', summoner.name)
+ dispatch('updateSettings', { name: 'recent_searches', value: state.recentSearches, isJson: true })
+ },
+ updateFavorite({ commit, dispatch, state }, summoner) {
+ const alreadyFav = state.favorites.find(s => s.name === summoner.name)
+ if (alreadyFav) {
+ commit('REMOVE_FAVORITE', summoner.name)
+ } else {
+ if (state.favorites.length >= 6) {
+ // Display error message
+ return dispatch('notification/add', {
+ type: 'error',
+ message: 'Too many favorite summoners.'
+ }, { root: true })
+ }
+ commit('ADD_FAVORITE', summoner)
+ }
+
+ dispatch('updateSettings', { name: 'favorites', value: state.favorites, isJson: true })
+ },
+ updatePercent({ commit }, percent) {
if (typeof (percent) !== 'boolean') {
percent = localStorage.getItem('settings-percent') === 'true'
} else {
@@ -23,12 +82,13 @@ export const actions = {
}
commit('UPDATE_PERCENT', percent)
},
- async updateSettings({ commit }, { name, value }) {
+ updateSettings({ commit }, { name, value, isJson = false }) {
if (!value) {
value = localStorage.getItem(name)
+ value = isJson ? JSON.parse(value) : value
if (!value) return
} else {
- localStorage.setItem(name, value)
+ localStorage.setItem(name, isJson ? JSON.stringify(value) : value)
}
commit(`UPDATE_${name.toUpperCase()}`, value)
}
diff --git a/client/src/store/modules/summoner.js b/client/src/store/modules/summoner.js
index 355da43..8634125 100644
--- a/client/src/store/modules/summoner.js
+++ b/client/src/store/modules/summoner.js
@@ -107,15 +107,22 @@ export const mutations = {
export const actions = {
async basicRequest({ commit, dispatch, rootState }, { summoner, region }) {
- region = rootState.regionsList[region]
+ const regionId = rootState.regionsList[region]
commit('BASIC_REQUEST')
try {
- const resp = await axios(({ url: 'summoner-basic', data: { summoner, region }, method: 'POST' }))
+ const resp = await axios(({ url: 'summoner-basic', data: { summoner, region: regionId }, method: 'POST' }))
if (resp.data) {
console.log(`---SUMMONER INFOS ${resp.data.account.name}---`)
console.log(resp.data)
const infos = createBasicSummonerData(resp.data)
commit('SUMMONER_FOUND', infos)
+
+ // Add summoner to recent searches
+ dispatch('settings/addRecentSearch', {
+ name: infos.account.name,
+ icon: infos.account.profileIconId,
+ region,
+ }, { root: true })
} else {
commit('SUMMONER_NOT_FOUND')
diff --git a/client/tailwind.config.js b/client/tailwind.config.js
index fd24e08..b62fb39 100644
--- a/client/tailwind.config.js
+++ b/client/tailwind.config.js
@@ -137,6 +137,7 @@ module.exports = {
'1': '0.25rem',
'2': '0.5rem',
'3': '0.75rem',
+ '3p5': '0.875rem',
'4': '1rem',
'4b': '1.15rem',
'5': '1.25rem',
@@ -326,6 +327,7 @@ module.exports = {
screen: '100vh',
},
maxWidth: {
+ '12': '3rem',
xs: '20rem',
sm: '24rem',
md: '28rem',