feat(breadcrumb_badges): display badge when editing is unlocked

This commit is contained in:
Elian Doran 2025-12-10 09:11:28 +02:00
parent f8b292dfa3
commit a810db3641
No known key found for this signature in database
3 changed files with 17 additions and 8 deletions

View File

@ -2133,6 +2133,7 @@
"breadcrumb_badges": { "breadcrumb_badges": {
"read_only_explicit": "Read-only", "read_only_explicit": "Read-only",
"read_only_auto": "Auto read-only", "read_only_auto": "Auto read-only",
"read_only_temporarily_disabled": "Temporarily editable",
"shared_publicly": "Shared publicly", "shared_publicly": "Shared publicly",
"shared_locally": "Shared locally" "shared_locally": "Shared locally"
} }

View File

@ -20,14 +20,22 @@ function ReadOnlyBadge() {
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");
const isTemporarilyEditable = noteContext?.viewScope?.readOnlyTemporarilyDisabled;
return (isReadOnly && if (isTemporarilyEditable) {
<Badge return <Badge
icon="bx bx-lock" icon="bx bx-lock-open-alt"
onClick={() => enableEditing(false)}
>
{t("breadcrumb_badges.read_only_temporarily_disabled")}
</Badge>;
} else if (isReadOnly) {
return <Badge
icon="bx bx-lock-alt"
onClick={() => enableEditing()}> onClick={() => enableEditing()}>
{isExplicitReadOnly ? t("breadcrumb_badges.read_only_explicit") : t("breadcrumb_badges.read_only_auto")} {isExplicitReadOnly ? t("breadcrumb_badges.read_only_explicit") : t("breadcrumb_badges.read_only_auto")}
</Badge> </Badge>;
); }
} }
function ShareBadge() { function ShareBadge() {

View File

@ -845,9 +845,9 @@ export function useGlobalShortcut(keyboardShortcut: string | null | undefined, h
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((enabled = true) => {
if (noteContext?.viewScope) { if (noteContext?.viewScope) {
noteContext.viewScope.readOnlyTemporarilyDisabled = true; noteContext.viewScope.readOnlyTemporarilyDisabled = enabled;
appContext.triggerEvent("readOnlyTemporarilyDisabled", {noteContext}); appContext.triggerEvent("readOnlyTemporarilyDisabled", {noteContext});
} }
}, [noteContext]); }, [noteContext]);
@ -862,7 +862,7 @@ export function useIsNoteReadOnly(note: FNote | null | undefined, noteContext: N
useTriliumEvent("readOnlyTemporarilyDisabled", ({noteContext: eventNoteContext}) => { useTriliumEvent("readOnlyTemporarilyDisabled", ({noteContext: eventNoteContext}) => {
if (noteContext?.ntxId === eventNoteContext.ntxId) { if (noteContext?.ntxId === eventNoteContext.ntxId) {
setIsReadOnly(false); setIsReadOnly(!noteContext.viewScope?.readOnlyTemporarilyDisabled);
} }
}); });