mirror of
https://github.com/zadam/trilium.git
synced 2025-11-09 14:55:50 +01:00
client: allow the isNoteReadOnly hook operate on a note and context other of the current one
This commit is contained in:
@@ -101,7 +101,7 @@ function ToggleReadOnlyButton({ note, viewType, isDefaultViewMode }: FloatingBut
|
|||||||
|
|
||||||
function EditButton({ note, noteContext, isDefaultViewMode }: FloatingButtonContext) {
|
function EditButton({ note, noteContext, isDefaultViewMode }: FloatingButtonContext) {
|
||||||
const [animationClass, setAnimationClass] = useState("");
|
const [animationClass, setAnimationClass] = useState("");
|
||||||
const {isReadOnly, enableEditing} = useIsNoteReadOnly();
|
const {isReadOnly, enableEditing} = useIsNoteReadOnly(note, noteContext);
|
||||||
|
|
||||||
// make the edit button stand out on the first display, otherwise
|
// make the edit button stand out on the first display, otherwise
|
||||||
// it's difficult to notice that the note is readonly
|
// it's difficult to notice that the note is readonly
|
||||||
|
|||||||
@@ -707,9 +707,8 @@ export function useResizeObserver(ref: RefObject<HTMLElement>, callback: () => v
|
|||||||
* Indicates that the current note is in read-only mode, while an editing mode is available,
|
* Indicates that the current note is in read-only mode, while an editing mode is available,
|
||||||
* and provides a way to switch to editing mode.
|
* and provides a way to switch to editing mode.
|
||||||
*/
|
*/
|
||||||
export function useIsNoteReadOnly() {
|
export function useIsNoteReadOnly(note: FNote | null | undefined, noteContext: NoteContext | undefined) {
|
||||||
const {note, noteContext} = useNoteContext();
|
const [isReadOnly, setIsReadOnly] = useState<boolean | undefined>(undefined);
|
||||||
const [isReadOnly, setIsReadOnly] = useState(false);
|
|
||||||
|
|
||||||
const enableEditing = useCallback(() => {
|
const enableEditing = useCallback(() => {
|
||||||
if (noteContext?.viewScope) {
|
if (noteContext?.viewScope) {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { useIsNoteReadOnly, useNoteContext, useTriliumEvent } from "./react/hook
|
|||||||
import Button from "./react/Button";
|
import Button from "./react/Button";
|
||||||
|
|
||||||
export default function ReadOnlyNoteInfoBar(props: {zenModeOnly?: boolean}) {
|
export default function ReadOnlyNoteInfoBar(props: {zenModeOnly?: boolean}) {
|
||||||
const {isReadOnly, enableEditing} = useIsNoteReadOnly();
|
const {note, noteContext} = useNoteContext();
|
||||||
const {note} = useNoteContext();
|
const {isReadOnly, enableEditing} = useIsNoteReadOnly(note, noteContext);
|
||||||
|
|
||||||
return <div class={`read-only-note-info-bar-widget ${(isReadOnly) ? "visible" : ""} ${(props.zenModeOnly) ? "zen-mode-only" : ""}`}>
|
return <div class={`read-only-note-info-bar-widget ${(isReadOnly) ? "visible" : ""} ${(props.zenModeOnly) ? "zen-mode-only" : ""}`}>
|
||||||
{isReadOnly && <>
|
{isReadOnly && <>
|
||||||
|
|||||||
Reference in New Issue
Block a user