stash
This commit is contained in:
parent
54374abf86
commit
8f3236b5b4
8 changed files with 156 additions and 160 deletions
|
|
@ -444,6 +444,31 @@ export default createStore({
|
|||
return null;
|
||||
}
|
||||
},
|
||||
// A group handle (leading '#') has no working owner-handle GET route yet
|
||||
// (get_shared_item, which fetchForeignItem calls, only resolves a personal
|
||||
// ToolshedUser handle) - resolve it instead via the already-correct, already-
|
||||
// authenticated group listing (?group=<id>, see fetchGroupInventoryItems) and pick the
|
||||
// matching item out of that, which only ever contains this one group's own items, so an
|
||||
// id collision with anything else can't happen. A personal/friend handle still goes
|
||||
// through fetchForeignItem as before.
|
||||
async fetchItemByHandle({dispatch, getters}, {handle, id}) {
|
||||
if (handle.startsWith('#')) {
|
||||
// groupIdByHandle is derived from state.idmap (see store.js's getters), which
|
||||
// nothing guarantees is loaded yet at this point - unlike Inventory.vue/
|
||||
// StorageLocation.vue/Print.vue, a direct or refreshed visit to an item's own
|
||||
// detail/edit page never fetched it. Loading it here, every time, is simplest;
|
||||
// fetchIdMap is cheap and already called unconditionally (no cache check) by
|
||||
// every other caller too.
|
||||
await dispatch('fetchIdMap')
|
||||
const groupId = getters.groupIdByHandle[handle]
|
||||
if (groupId === undefined) {
|
||||
return null
|
||||
}
|
||||
const items = await dispatch('fetchGroupInventoryItems', groupId)
|
||||
return items.find(item => item.id === parseInt(id)) || null
|
||||
}
|
||||
return dispatch('fetchForeignItem', {owner: handle, id})
|
||||
},
|
||||
async fetchFriendRequests({state, dispatch, getters}) {
|
||||
const servers = await dispatch('getHomeServers')
|
||||
return await servers.get(getters.signAuth, '/api/friendrequests/')
|
||||
|
|
@ -802,6 +827,15 @@ export default createStore({
|
|||
groupIdByHandle(state) {
|
||||
return Object.fromEntries(state.idmap.groups.map(g => [g.handle, g.id]))
|
||||
},
|
||||
// Reverse of the two getters above - turns a short-id's raw owner_identity_id/
|
||||
// owner_group_id back into a handle (see router.js's EXPANDED_ROUTE_BUILDERS), without
|
||||
// a separate backend lookup since the idmap already has both directions of this data.
|
||||
identityHandleById(state) {
|
||||
return Object.fromEntries(state.idmap.identities.map(i => [i.id, i.username]))
|
||||
},
|
||||
groupHandleById(state) {
|
||||
return Object.fromEntries(state.idmap.groups.map(g => [g.id, g.handle]))
|
||||
},
|
||||
loaded_items(state) {
|
||||
return Object.entries(state.item_map).reduce((acc, [url, items]) => {
|
||||
return acc.concat(items)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue