1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-23 15:24:21 +00:00
sophon/frontend/src/components/group/useGroupMembership.ts

31 lines
865 B
TypeScript
Raw Normal View History

2021-10-20 20:39:19 +00:00
import * as React from "react"
import {useAuthorizationContext} from "../../contexts/authorization"
import {useGroupContext} from "../../contexts/group"
export function useGroupMembership(): boolean | undefined {
const authorization = useAuthorizationContext()
const group = useGroupContext()
return React.useMemo(
() => {
if(!authorization) {
return undefined
}
if(!group) {
return undefined
}
if(!authorization.state.token) {
return false
}
if(!(
group.value.members.includes(authorization.state.user.id) || group.value.owner === authorization.state.user.id
)) {
return false
}
return true
},
[authorization, group]
)
}