diff --git a/frontend/src/store.js b/frontend/src/store.js index b047e16..6a13b68 100644 --- a/frontend/src/store.js +++ b/frontend/src/store.js @@ -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 { diff --git a/frontend/src/views/Inventory.vue b/frontend/src/views/Inventory.vue index 8e51e75..82e6196 100644 --- a/frontend/src/views/Inventory.vue +++ b/frontend/src/views/Inventory.vue @@ -77,7 +77,7 @@
- + Add
@@ -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() } }