1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-23 07:14:21 +00:00

🔧 Count the owner of the group in its members

This commit is contained in:
Steffo 2021-10-11 18:53:28 +02:00
parent c1bf5978ac
commit 57f283ef74
Signed by: steffo
GPG key ID: 6965406171929D01
3 changed files with 9 additions and 4 deletions

View file

@ -15,6 +15,8 @@ export interface GroupJoinButtonProps {
export function GroupJoinButton({resource}: GroupJoinButtonProps): JSX.Element | null { export function GroupJoinButton({resource}: GroupJoinButtonProps): JSX.Element | null {
const authorization = useAuthorizationContext() const authorization = useAuthorizationContext()
const trueMembers = [resource.value.owner, ...resource.value.members]
const doJoin = const doJoin =
React.useCallback( React.useCallback(
async () => { async () => {
@ -29,7 +31,7 @@ export function GroupJoinButton({resource}: GroupJoinButtonProps): JSX.Element |
if(!authorization.state.user) { if(!authorization.state.user) {
return null return null
} }
if(resource.value.members.includes(authorization.state.user.id)) { if(trueMembers.includes(authorization.state.user.id)) {
return null return null
} }

View file

@ -15,6 +15,8 @@ export interface GroupLeaveButtonProps {
export function GroupLeaveButton({resource}: GroupLeaveButtonProps): JSX.Element | null { export function GroupLeaveButton({resource}: GroupLeaveButtonProps): JSX.Element | null {
const authorization = useAuthorizationContext() const authorization = useAuthorizationContext()
const trueMembers = [resource.value.owner, ...resource.value.members]
const doLeave = const doLeave =
React.useCallback( React.useCallback(
async () => { async () => {
@ -29,7 +31,7 @@ export function GroupLeaveButton({resource}: GroupLeaveButtonProps): JSX.Element
if(!authorization.state.user) { if(!authorization.state.user) {
return null return null
} }
if(!resource.value.members.includes(authorization.state.user.id)) { if(!trueMembers.includes(authorization.state.user.id)) {
return null return null
} }

View file

@ -16,7 +16,8 @@ export interface GroupResourcePanelProps {
export function GroupResourcePanel({resource}: GroupResourcePanelProps): JSX.Element { export function GroupResourcePanel({resource}: GroupResourcePanelProps): JSX.Element {
const icon = resource.value.access === "OPEN" ? faGlobe : faEnvelope const icon = resource.value.access === "OPEN" ? faGlobe : faEnvelope
const members = resource.value.members.length
const trueMembers = [resource.value.owner, ...resource.value.members]
return ( return (
<ResourcePanel> <ResourcePanel>
@ -29,7 +30,7 @@ export function GroupResourcePanel({resource}: GroupResourcePanelProps): JSX.Ele
</Link> </Link>
</ResourcePanel.Name> </ResourcePanel.Name>
<ResourcePanel.Text> <ResourcePanel.Text>
{members} member{members !== 1 ? "s" : ""} {trueMembers.length} member{trueMembers.length !== 1 ? "s" : ""}
</ResourcePanel.Text> </ResourcePanel.Text>
<ResourcePanel.Buttons> <ResourcePanel.Buttons>
<GroupLeaveButton resource={resource}/> <GroupLeaveButton resource={resource}/>