stash
This commit is contained in:
parent
34942cedda
commit
df70a347e3
2 changed files with 6 additions and 21 deletions
|
@ -52,6 +52,7 @@ export default createStore({
|
|||
localStorage.setItem('remember', remember);
|
||||
},
|
||||
setInventoryItems(state, {url, items}) {
|
||||
console.log('setInventoryItems', url, items)
|
||||
state.item_map[url] = items;
|
||||
},
|
||||
setFriends(state, friends) {
|
||||
|
@ -109,13 +110,12 @@ export default createStore({
|
|||
actions: {
|
||||
async login({commit, dispatch, state, getters}, {username, password, remember}) {
|
||||
commit('setRemember', remember);
|
||||
const data = await dispatch('lookupServer', {username}).then(servers => new ServerSet(servers, state.unreachable_neighbors))
|
||||
.then(set => set.post(getters.nullAuth, '/auth/token/', {username, password}))
|
||||
const s = await dispatch('lookupServer', {username}).then(servers => new ServerSet(servers, state.unreachable_neighbors))
|
||||
const data = await s.post(getters.nullAuth, '/auth/token/', {username, password})
|
||||
if (data.token && data.key) {
|
||||
commit('setToken', data.token);
|
||||
commit('setUser', username);
|
||||
commit('setKey', data.key);
|
||||
const s = await dispatch('lookupServer', {username}).then(servers => new ServerSet(servers, state.unreachable_neighbors))
|
||||
commit('setHomeServers', s)
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
|
||||
</div>
|
||||
<div class="card">
|
||||
<button class="btn" @click="getInventoryItems">Refresh</button>
|
||||
<button class="btn" @click="fetchInventoryItems">Refresh</button>
|
||||
<router-link to="/inventory/new" class="btn btn-primary">Add</router-link>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -110,25 +110,10 @@ export default {
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions(["apiFederatedGet", "getFriends", "getFriendServer"]),
|
||||
...mapMutations(["setInventoryItems"]),
|
||||
async getInventoryItems() {
|
||||
try {
|
||||
const servers = await this.getFriends().then(friends => friends.map(friend => this.getFriendServer({username: friend})))
|
||||
const urls = servers.map(server => server.then(s => {
|
||||
return {host: s, target: "/api/inventory_items/"}
|
||||
}))
|
||||
urls.map(url => url.then(u => this.apiFederatedGet(u).then(items => {
|
||||
this.setInventoryItems({url: u.domain, items})
|
||||
}).catch(e => {
|
||||
}))) // TODO: handle error
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
...mapActions(["fetchInventoryItems"]),
|
||||
},
|
||||
async mounted() {
|
||||
await this.getInventoryItems()
|
||||
await this.fetchInventoryItems()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue