Skip to content

Commit

Permalink
Merge pull request #414 from dappforce/permission
Browse files Browse the repository at this point in the history
Fix space permission issue
  • Loading branch information
teodorus-nathaniel authored Apr 24, 2024
2 parents 630977d + c138c42 commit 6b12284
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/rtk/features/spaces/spacesSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,20 @@ const getSpaces = createFetchDataFn<SpaceState[]>([])({
}
return entities
},
squid: async ({ ids }: { ids: string[] }, client) => {
const spaces = await getSpacesData(client, { where: { id_in: ids } })
return spaces.map<SpaceState>(space => ({ ...space, isOverview: true }))
squid: async ({ api, ids }: { api: SubsocialApi; ids: string[] }, client) => {
// need to fetch from chain to get correct permissions, while fetch from squid to prefetch the content
const [spaces, spacesFromChain] = await Promise.all([
getSpacesData(client, { where: { id_in: ids } }),
api.findSpaceStructs(ids),
] as const)
const spacesFromChainMap = new Map<string, SpaceStruct>()
spacesFromChain.forEach(space => spacesFromChainMap.set(space.id, space))

return spaces.map<SpaceState>(space => ({
...space,
...spacesFromChainMap.get(space.id),
isOverview: false,
}))
},
})
export const fetchSpaces = createAsyncThunk<SpaceStruct[], FetchSpacesArgs, ThunkApiConfig>(
Expand Down Expand Up @@ -201,7 +212,7 @@ export const fetchSpaces = createAsyncThunk<SpaceStruct[], FetchSpacesArgs, Thun
const newIds = _newIds as string[]
const entities = await getSpaces(dataSource, {
chain: { api, ids: idsToBns(newIds) },
squid: { ids: newIds },
squid: { ids: newIds, api },
})
if (dataSource === DataSourceTypes.CHAIN) {
await getSpacesCountDataFromChain(api, entities)
Expand Down

0 comments on commit 6b12284

Please sign in to comment.