Skip to content

Commit

Permalink
fix: make sure to show communities without roles
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Nov 18, 2024
1 parent 29a9f28 commit 25ce5a1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export class ApiCommunityDataService {

async getCommunities(username: string) {
return this.core.data.community.findMany({
where: {
// Ensure that the role has at least one condition
roles: { some: { conditions: { some: {} } } },
},
include: {
roles: {
// Ensure that the role has at least one condition
Expand Down
65 changes: 35 additions & 30 deletions libs/web/community/ui/src/lib/community-ui-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function CommunityUiListItem({
to?: string
username: string
}) {
const hasRoles = item.roles?.length
const rolesAssigned = item.roles?.filter((role) => role.member)
const rolesAvailable = item.roles?.filter((role) => !role.member)
return (
Expand All @@ -31,36 +32,40 @@ export function CommunityUiListItem({
</CommunityUiSocials>
</UiStack>
</UiGroup>
<Suspense fallback={<UiLoader />}>
<Box>
<Text fz="sm" c="dimmed">
Roles assigned to {isAuthUser ? 'you' : username}
</Text>
{rolesAssigned?.length ? (
<RoleUiList mt="xs" roles={rolesAssigned} username={username} withAssets />
) : (
<UiInfo
mt="xs"
title="No roles assigned"
message={`${isAuthUser ? 'You have' : `${username} has`} no assigned roles in this community.`}
/>
)}
</Box>
<Box>
<Text fz="sm" c="dimmed">
Available roles
</Text>
{rolesAvailable?.length ? (
<RoleUiList mt="xs" roles={rolesAvailable} username={username} />
) : (
<UiInfo
mt="xs"
title="All roles are assigned"
message={`${isAuthUser ? 'You have' : `${username} has`} all available roles assigned.`}
/>
)}
</Box>
</Suspense>
{hasRoles ? (
<Suspense fallback={<UiLoader />}>
<Box>
<Text fz="sm" c="dimmed">
Roles assigned to {isAuthUser ? 'you' : username}
</Text>
{rolesAssigned?.length ? (
<RoleUiList mt="xs" roles={rolesAssigned} username={username} withAssets />
) : (
<UiInfo
mt="xs"
title="No roles assigned"
message={`${isAuthUser ? 'You have' : `${username} has`} no assigned roles in this community.`}
/>
)}
</Box>
<Box>
<Text fz="sm" c="dimmed">
Available roles
</Text>
{rolesAvailable?.length ? (
<RoleUiList mt="xs" roles={rolesAvailable} username={username} />
) : (
<UiInfo
mt="xs"
title="All roles are assigned"
message={`${isAuthUser ? 'You have' : `${username} has`} all available roles assigned.`}
/>
)}
</Box>
</Suspense>
) : (
<UiInfo title="No roles defined" message="This community has no roles defined." />
)}
</UiStack>
</Paper>
)
Expand Down
20 changes: 9 additions & 11 deletions libs/web/community/ui/src/lib/community-ui-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ export function CommunityUiList({
}
return (
<UiStack>
{communities
.filter((item) => item.roles?.length)
.map((item) => (
<CommunityUiListItem
key={item.id}
isAuthUser={isAuthUser}
item={item}
to={`/c/${item.id}`}
username={username}
/>
))}
{communities.map((item) => (
<CommunityUiListItem
key={item.id}
isAuthUser={isAuthUser}
item={item}
to={`/c/${item.id}`}
username={username}
/>
))}
</UiStack>
)
}

0 comments on commit 25ce5a1

Please sign in to comment.