yunohost-admin/app/src/helpers/dataStore.js

31 lines
750 B
JavaScript
Raw Normal View History

import api from './api'
export default {
state: () => ({
2020-07-16 16:30:19 +02:00
domains: undefined,
users: undefined
}),
mutations: {
2020-07-16 16:30:19 +02:00
'SET_DOMAINS' (state, domains) {
state.domains = domains
},
'SET_USERS' (state, users) {
console.log(users)
state.users = Object.keys(users).length === 0 ? null : Object.values(users)
}
},
actions: {
2020-07-16 19:18:01 +02:00
async 'FETCH' ({ state, commit }, { uri, force = false }) {
// if data has already been queried, simply return
if (state[uri] !== undefined && !force) return
2020-07-16 16:30:19 +02:00
return api.get(uri).then(responseData => {
const data = responseData[uri] ? responseData[uri] : responseData
commit('SET_' + uri.toUpperCase(), data)
})
}
},
getters: {
}
}