fix(read-only-bar): displayed when viewing attachments

This commit is contained in:
Elian Doran 2025-11-29 19:40:00 +02:00
parent f325930f68
commit c9aa992e73
No known key found for this signature in database
2 changed files with 25 additions and 23 deletions

View File

@ -6,28 +6,30 @@ import InfoBar from "./react/InfoBar";
import HelpButton from "./react/HelpButton"; import HelpButton from "./react/HelpButton";
export default function ReadOnlyNoteInfoBar(props: {}) { export default function ReadOnlyNoteInfoBar(props: {}) {
const {note, noteContext} = useNoteContext(); const { note, noteContext } = useNoteContext();
const {isReadOnly, enableEditing} = useIsNoteReadOnly(note, noteContext); const { isReadOnly, enableEditing } = useIsNoteReadOnly(note, noteContext);
const isExplicitReadOnly = note?.isLabelTruthy("readOnly"); const isExplicitReadOnly = note?.isLabelTruthy("readOnly");
return <InfoBar className="read-only-note-info-bar-widget" return (
type={(isExplicitReadOnly ? "subtle" : "prominent")} <InfoBar
style={{display: (!isReadOnly) ? "none" : undefined}}> className="read-only-note-info-bar-widget"
type={(isExplicitReadOnly ? "subtle" : "prominent")}
<div class="read-only-note-info-bar-widget-content"> style={{display: (!isReadOnly) ? "none" : undefined}}
{(isExplicitReadOnly) ? ( >
<div>{t("read-only-info.read-only-note")}</div> <div class="read-only-note-info-bar-widget-content">
) : ( {(isExplicitReadOnly) ? (
<div> <div>{t("read-only-info.read-only-note")}</div>
{t("read-only-info.auto-read-only-note")} ) : (
{" "} <div>
<HelpButton helpPage="CoFPLs3dRlXc" /> {t("read-only-info.auto-read-only-note")}
</div> {" "}
)} <HelpButton helpPage="CoFPLs3dRlXc" />
<Button text={t("read-only-info.edit-note")}
icon="bx-pencil" onClick={() => enableEditing()} />
</div> </div>
</InfoBar> )}
<Button text={t("read-only-info.edit-note")}
icon="bx-pencil" onClick={() => enableEditing()} />
</div>
</InfoBar>
);
} }

View File

@ -795,7 +795,7 @@ export function useKeyboardShortcuts(scope: "code-detail" | "text-detail", conta
* and provides a way to switch to editing mode. * and provides a way to switch to editing mode.
*/ */
export function useIsNoteReadOnly(note: FNote | null | undefined, noteContext: NoteContext | undefined) { export function useIsNoteReadOnly(note: FNote | null | undefined, noteContext: NoteContext | undefined) {
const [isReadOnly, setIsReadOnly] = useState<boolean | undefined>(undefined); const [ isReadOnly, setIsReadOnly ] = useState<boolean | undefined>(undefined);
const enableEditing = useCallback(() => { const enableEditing = useCallback(() => {
if (noteContext?.viewScope) { if (noteContext?.viewScope) {
@ -810,7 +810,7 @@ export function useIsNoteReadOnly(note: FNote | null | undefined, noteContext: N
setIsReadOnly(readOnly); setIsReadOnly(readOnly);
}); });
} }
}, [note, noteContext]); }, [ note, noteContext, noteContext?.viewScope ]);
useTriliumEvent("readOnlyTemporarilyDisabled", ({noteContext: eventNoteContext}) => { useTriliumEvent("readOnlyTemporarilyDisabled", ({noteContext: eventNoteContext}) => {
if (noteContext?.ntxId === eventNoteContext.ntxId) { if (noteContext?.ntxId === eventNoteContext.ntxId) {
@ -818,7 +818,7 @@ export function useIsNoteReadOnly(note: FNote | null | undefined, noteContext: N
} }
}); });
return {isReadOnly, enableEditing}; return { isReadOnly, enableEditing };
} }
async function isNoteReadOnly(note: FNote, noteContext: NoteContext) { async function isNoteReadOnly(note: FNote, noteContext: NoteContext) {