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:
Philip Molares 2023-03-24 16:08:42 +01:00 committed by Tilman Vatteroth
parent 81531b6559
commit 107ec7a522

View 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])
}