mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-22 20:30:49 +00:00
feat(frontend): add isOwner hook
This hook is used to determine if the current user is the owner of the note Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
81531b6559
commit
107ec7a522
1 changed files with 19 additions and 0 deletions
19
frontend/src/hooks/common/use-is-owner.ts
Normal file
19
frontend/src/hooks/common/use-is-owner.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { useApplicationState } from './use-application-state'
|
||||
import { useMemo } from 'react'
|
||||
|
||||
/**
|
||||
* Determines if the current user is the owner of the current note.
|
||||
*
|
||||
* @return True, if the current user is owner.
|
||||
*/
|
||||
export const useIsOwner = (): boolean => {
|
||||
const owner = useApplicationState((state) => state.noteDetails.permissions.owner)
|
||||
const me: string | undefined = useApplicationState((state) => state.user?.username)
|
||||
|
||||
return useMemo(() => !!me && owner === me, [owner, me])
|
||||
}
|
Loading…
Reference in a new issue