mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-27 13:34:28 -04:00

Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
21 lines
769 B
TypeScript
21 lines
769 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
import { useApplicationState } from './use-application-state'
|
|
import type { NotePermissions } from '@hedgedoc/commons'
|
|
import { userCanEdit } from '@hedgedoc/commons'
|
|
import { useMemo } from 'react'
|
|
|
|
/**
|
|
* Determines if the current user is allowed to write to this note.
|
|
*
|
|
* @return True, if the current user is allowed to write.
|
|
*/
|
|
export const useMayEdit = (): boolean => {
|
|
const me: string | undefined = useApplicationState((state) => state.user?.username)
|
|
const permissions: NotePermissions = useApplicationState((state) => state.noteDetails.permissions)
|
|
|
|
return useMemo(() => userCanEdit(permissions, me), [permissions, me])
|
|
}
|