fix users state when removing the last user and fix 'cached' check

This commit is contained in:
Axolotle 2020-11-25 18:35:35 +01:00
parent 4dd44ec9d1
commit ad5c0c0cde

View file

@ -1,6 +1,8 @@
import Vue from 'vue'
import api from '@/api'
export default {
state: () => ({
domains: undefined, // Array
@ -37,7 +39,7 @@ export default {
},
'ADD_USERS' (state, user) {
if (state.users === undefined) state.users = {}
if (!state.users) state.users = {}
Vue.set(state.users, user.username, user)
},
@ -62,6 +64,9 @@ export default {
Vue.delete(state.users_details, username)
if (state.users) {
Vue.delete(state.users, username)
if (Object.keys(state.users).length === 0) {
state.users = null
}
}
},
@ -108,8 +113,8 @@ export default {
return { storeKey, param, responseData }
})
})).then(responsesData => {
return responsesData.map(({ storeKey, param, responseData, cached = null }) => {
if (cached) return cached
return responsesData.map(({ storeKey, param, responseData, cached = undefined }) => {
if (cached !== undefined) return cached
const data = responseData[storeKey] ? responseData[storeKey] : responseData
commit('SET_' + storeKey.toUpperCase(), param ? [param, data] : data)
return param ? state[storeKey][param] : state[storeKey]
@ -146,8 +151,8 @@ export default {
users: state => state.users,
userNames: state => {
if (state.users !== undefined) return Object.keys(state.users)
return undefined
if (state.users) return Object.keys(state.users)
return []
},
usersAsChoices: state => {