mirror of
https://github.com/Steffo99/sophon.git
synced 2024-12-22 14:54:22 +00:00
🔧 Count the owner of the group in its members
This commit is contained in:
parent
36c5ead53d
commit
0c487473e2
3 changed files with 9 additions and 4 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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}/>
|
||||||
|
|
Loading…
Reference in a new issue