mirror of
https://github.com/zadam/trilium.git
synced 2025-12-20 14:24:27 +01:00
fix(badges): "temporarily editable" remaining after changing editability
This commit is contained in:
parent
90a7217b32
commit
737e5b85b4
@ -22,11 +22,10 @@ export default function NoteBadges() {
|
|||||||
|
|
||||||
function ReadOnlyBadge() {
|
function ReadOnlyBadge() {
|
||||||
const { note, noteContext } = useNoteContext();
|
const { note, noteContext } = useNoteContext();
|
||||||
const { isReadOnly, enableEditing } = useIsNoteReadOnly(note, noteContext);
|
const { isReadOnly, enableEditing, temporarilyEditable } = useIsNoteReadOnly(note, noteContext);
|
||||||
const isExplicitReadOnly = note?.isLabelTruthy("readOnly");
|
const isExplicitReadOnly = note?.isLabelTruthy("readOnly");
|
||||||
const isTemporarilyEditable = noteContext?.ntxId !== "_popup-editor" && noteContext?.viewScope?.readOnlyTemporarilyDisabled;
|
|
||||||
|
|
||||||
if (isTemporarilyEditable) {
|
if (temporarilyEditable) {
|
||||||
return <Badge
|
return <Badge
|
||||||
icon="bx bx-lock-open-alt"
|
icon="bx bx-lock-open-alt"
|
||||||
text={t("breadcrumb_badges.read_only_temporarily_disabled")}
|
text={t("breadcrumb_badges.read_only_temporarily_disabled")}
|
||||||
|
|||||||
@ -933,11 +933,13 @@ export function useIsNoteReadOnly(note: FNote | null | undefined, noteContext: N
|
|||||||
const [ isReadOnly, setIsReadOnly ] = useState<boolean | undefined>(undefined);
|
const [ isReadOnly, setIsReadOnly ] = useState<boolean | undefined>(undefined);
|
||||||
const [ readOnlyAttr ] = useNoteLabelBoolean(note, "readOnly");
|
const [ readOnlyAttr ] = useNoteLabelBoolean(note, "readOnly");
|
||||||
const [ autoReadOnlyDisabledAttr ] = useNoteLabelBoolean(note, "autoReadOnlyDisabled");
|
const [ autoReadOnlyDisabledAttr ] = useNoteLabelBoolean(note, "autoReadOnlyDisabled");
|
||||||
|
const [ temporarilyEditable, setTemporarilyEditable ] = useState(false);
|
||||||
|
|
||||||
const enableEditing = useCallback((enabled = true) => {
|
const enableEditing = useCallback((enabled = true) => {
|
||||||
if (noteContext?.viewScope) {
|
if (noteContext?.viewScope) {
|
||||||
noteContext.viewScope.readOnlyTemporarilyDisabled = enabled;
|
noteContext.viewScope.readOnlyTemporarilyDisabled = enabled;
|
||||||
appContext.triggerEvent("readOnlyTemporarilyDisabled", {noteContext});
|
appContext.triggerEvent("readOnlyTemporarilyDisabled", {noteContext});
|
||||||
|
setTemporarilyEditable(enabled);
|
||||||
}
|
}
|
||||||
}, [noteContext]);
|
}, [noteContext]);
|
||||||
|
|
||||||
@ -945,6 +947,7 @@ export function useIsNoteReadOnly(note: FNote | null | undefined, noteContext: N
|
|||||||
if (note && noteContext) {
|
if (note && noteContext) {
|
||||||
isNoteReadOnly(note, noteContext).then((readOnly) => {
|
isNoteReadOnly(note, noteContext).then((readOnly) => {
|
||||||
setIsReadOnly(readOnly);
|
setIsReadOnly(readOnly);
|
||||||
|
setTemporarilyEditable(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [ note, noteContext, noteContext?.viewScope, readOnlyAttr, autoReadOnlyDisabledAttr ]);
|
}, [ note, noteContext, noteContext?.viewScope, readOnlyAttr, autoReadOnlyDisabledAttr ]);
|
||||||
@ -952,10 +955,11 @@ 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(!noteContext.viewScope?.readOnlyTemporarilyDisabled);
|
setIsReadOnly(!noteContext.viewScope?.readOnlyTemporarilyDisabled);
|
||||||
|
setTemporarilyEditable(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return { isReadOnly, enableEditing };
|
return { isReadOnly, enableEditing, temporarilyEditable };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function isNoteReadOnly(note: FNote, noteContext: NoteContext) {
|
async function isNoteReadOnly(note: FNote, noteContext: NoteContext) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user