enhancement(sidebar): hide delete note button when not being the owner

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2023-10-08 11:32:53 +02:00 committed by Tilman Vatteroth
parent f786fe538b
commit e53ad15bfe

View file

@ -16,6 +16,7 @@ import type { PropsWithChildren } from 'react'
import React, { Fragment, useCallback } from 'react' import React, { Fragment, useCallback } from 'react'
import { Trash as IconTrash } from 'react-bootstrap-icons' import { Trash as IconTrash } from 'react-bootstrap-icons'
import { Trans, useTranslation } from 'react-i18next' import { Trans, useTranslation } from 'react-i18next'
import { useIsOwner } from '../../../../../hooks/common/use-is-owner'
/** /**
* Sidebar entry that can be used to delete the current note. * Sidebar entry that can be used to delete the current note.
@ -25,6 +26,7 @@ import { Trans, useTranslation } from 'react-i18next'
*/ */
export const DeleteNoteSidebarEntry: React.FC<PropsWithChildren<SpecificSidebarEntryProps>> = ({ hide, className }) => { export const DeleteNoteSidebarEntry: React.FC<PropsWithChildren<SpecificSidebarEntryProps>> = ({ hide, className }) => {
useTranslation() useTranslation()
const userIsOwner = useIsOwner()
const router = useRouter() const router = useRouter()
const noteId = useApplicationState((state) => state.noteDetails?.id) const noteId = useApplicationState((state) => state.noteDetails?.id)
const [modalVisibility, showModal, closeModal] = useBooleanState() const [modalVisibility, showModal, closeModal] = useBooleanState()
@ -40,6 +42,10 @@ export const DeleteNoteSidebarEntry: React.FC<PropsWithChildren<SpecificSidebarE
.finally(closeModal) .finally(closeModal)
}, [closeModal, noteId, router, showErrorNotification]) }, [closeModal, noteId, router, showErrorNotification])
if (!userIsOwner) {
return null
}
return ( return (
<Fragment> <Fragment>
<SidebarButton <SidebarButton