mirror of
https://github.com/zadam/trilium.git
synced 2025-12-21 14:54:24 +01:00
feat(breadcrumb): react to hosted note ID change
This commit is contained in:
parent
83777d7ea0
commit
af3883fdac
@ -275,6 +275,7 @@ export function useNoteContext() {
|
|||||||
const [ noteContext, setNoteContext ] = useState<NoteContext | undefined>(noteContextContext ?? undefined);
|
const [ noteContext, setNoteContext ] = useState<NoteContext | undefined>(noteContextContext ?? undefined);
|
||||||
const [ notePath, setNotePath ] = useState<string | null | undefined>();
|
const [ notePath, setNotePath ] = useState<string | null | undefined>();
|
||||||
const [ note, setNote ] = useState<FNote | null | undefined>();
|
const [ note, setNote ] = useState<FNote | null | undefined>();
|
||||||
|
const [ hoistedNoteId, setHoistedNoteId ] = useState(noteContext?.hoistedNoteId);
|
||||||
const [ , setViewScope ] = useState<ViewScope>();
|
const [ , setViewScope ] = useState<ViewScope>();
|
||||||
const [ isReadOnlyTemporarilyDisabled, setIsReadOnlyTemporarilyDisabled ] = useState<boolean | null | undefined>(noteContext?.viewScope?.isReadOnly);
|
const [ isReadOnlyTemporarilyDisabled, setIsReadOnlyTemporarilyDisabled ] = useState<boolean | null | undefined>(noteContext?.viewScope?.isReadOnly);
|
||||||
const [ refreshCounter, setRefreshCounter ] = useState(0);
|
const [ refreshCounter, setRefreshCounter ] = useState(0);
|
||||||
@ -282,6 +283,7 @@ export function useNoteContext() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!noteContextContext) return;
|
if (!noteContextContext) return;
|
||||||
setNoteContext(noteContextContext);
|
setNoteContext(noteContextContext);
|
||||||
|
setHoistedNoteId(noteContextContext.hoistedNoteId);
|
||||||
setNote(noteContextContext.note);
|
setNote(noteContextContext.note);
|
||||||
setNotePath(noteContextContext.notePath);
|
setNotePath(noteContextContext.notePath);
|
||||||
setViewScope(noteContextContext.viewScope);
|
setViewScope(noteContextContext.viewScope);
|
||||||
@ -295,6 +297,7 @@ export function useNoteContext() {
|
|||||||
useTriliumEvents([ "setNoteContext", "activeContextChanged", "noteSwitchedAndActivated", "noteSwitched" ], ({ noteContext }) => {
|
useTriliumEvents([ "setNoteContext", "activeContextChanged", "noteSwitchedAndActivated", "noteSwitched" ], ({ noteContext }) => {
|
||||||
if (noteContextContext) return;
|
if (noteContextContext) return;
|
||||||
setNoteContext(noteContext);
|
setNoteContext(noteContext);
|
||||||
|
setHoistedNoteId(noteContext.hoistedNoteId);
|
||||||
setNotePath(noteContext.notePath);
|
setNotePath(noteContext.notePath);
|
||||||
setViewScope(noteContext.viewScope);
|
setViewScope(noteContext.viewScope);
|
||||||
});
|
});
|
||||||
@ -312,6 +315,11 @@ export function useNoteContext() {
|
|||||||
setIsReadOnlyTemporarilyDisabled(eventNoteContext?.viewScope?.readOnlyTemporarilyDisabled);
|
setIsReadOnlyTemporarilyDisabled(eventNoteContext?.viewScope?.readOnlyTemporarilyDisabled);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
useTriliumEvent("hoistedNoteChanged", ({ noteId, ntxId }) => {
|
||||||
|
if (ntxId === noteContext?.ntxId) {
|
||||||
|
setHoistedNoteId(noteId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const parentComponent = useContext(ParentComponent) as ReactWrappedWidget;
|
const parentComponent = useContext(ParentComponent) as ReactWrappedWidget;
|
||||||
useDebugValue(() => `notePath=${notePath}, ntxId=${noteContext?.ntxId}`);
|
useDebugValue(() => `notePath=${notePath}, ntxId=${noteContext?.ntxId}`);
|
||||||
@ -320,7 +328,7 @@ export function useNoteContext() {
|
|||||||
note,
|
note,
|
||||||
noteId: noteContext?.note?.noteId,
|
noteId: noteContext?.note?.noteId,
|
||||||
notePath: noteContext?.notePath,
|
notePath: noteContext?.notePath,
|
||||||
hoistedNoteId: noteContext?.hoistedNoteId,
|
hoistedNoteId,
|
||||||
ntxId: noteContext?.ntxId,
|
ntxId: noteContext?.ntxId,
|
||||||
viewScope: noteContext?.viewScope,
|
viewScope: noteContext?.viewScope,
|
||||||
componentId: parentComponent.componentId,
|
componentId: parentComponent.componentId,
|
||||||
@ -339,6 +347,7 @@ export function useActiveNoteContext() {
|
|||||||
const [ notePath, setNotePath ] = useState<string | null | undefined>();
|
const [ notePath, setNotePath ] = useState<string | null | undefined>();
|
||||||
const [ note, setNote ] = useState<FNote | null | undefined>();
|
const [ note, setNote ] = useState<FNote | null | undefined>();
|
||||||
const [ , setViewScope ] = useState<ViewScope>();
|
const [ , setViewScope ] = useState<ViewScope>();
|
||||||
|
const [ hoistedNoteId, setHoistedNoteId ] = useState(noteContext?.hoistedNoteId);
|
||||||
const [ isReadOnlyTemporarilyDisabled, setIsReadOnlyTemporarilyDisabled ] = useState<boolean | null | undefined>(noteContext?.viewScope?.isReadOnly);
|
const [ isReadOnlyTemporarilyDisabled, setIsReadOnlyTemporarilyDisabled ] = useState<boolean | null | undefined>(noteContext?.viewScope?.isReadOnly);
|
||||||
const [ refreshCounter, setRefreshCounter ] = useState(0);
|
const [ refreshCounter, setRefreshCounter ] = useState(0);
|
||||||
|
|
||||||
@ -355,6 +364,7 @@ export function useActiveNoteContext() {
|
|||||||
useTriliumEvents([ "setNoteContext", "activeContextChanged", "noteSwitchedAndActivated", "noteSwitched" ], () => {
|
useTriliumEvents([ "setNoteContext", "activeContextChanged", "noteSwitchedAndActivated", "noteSwitched" ], () => {
|
||||||
const noteContext = appContext.tabManager.getActiveContext() ?? undefined;
|
const noteContext = appContext.tabManager.getActiveContext() ?? undefined;
|
||||||
setNoteContext(noteContext);
|
setNoteContext(noteContext);
|
||||||
|
setHoistedNoteId(noteContext?.hoistedNoteId);
|
||||||
setNotePath(noteContext?.notePath);
|
setNotePath(noteContext?.notePath);
|
||||||
setViewScope(noteContext?.viewScope);
|
setViewScope(noteContext?.viewScope);
|
||||||
});
|
});
|
||||||
@ -371,6 +381,11 @@ export function useActiveNoteContext() {
|
|||||||
setIsReadOnlyTemporarilyDisabled(eventNoteContext?.viewScope?.readOnlyTemporarilyDisabled);
|
setIsReadOnlyTemporarilyDisabled(eventNoteContext?.viewScope?.readOnlyTemporarilyDisabled);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
useTriliumEvent("hoistedNoteChanged", ({ noteId, ntxId }) => {
|
||||||
|
if (ntxId === noteContext?.ntxId) {
|
||||||
|
setHoistedNoteId(noteId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const parentComponent = useContext(ParentComponent) as ReactWrappedWidget;
|
const parentComponent = useContext(ParentComponent) as ReactWrappedWidget;
|
||||||
useDebugValue(() => `notePath=${notePath}, ntxId=${noteContext?.ntxId}`);
|
useDebugValue(() => `notePath=${notePath}, ntxId=${noteContext?.ntxId}`);
|
||||||
@ -379,7 +394,7 @@ export function useActiveNoteContext() {
|
|||||||
note,
|
note,
|
||||||
noteId: noteContext?.note?.noteId,
|
noteId: noteContext?.note?.noteId,
|
||||||
notePath: noteContext?.notePath,
|
notePath: noteContext?.notePath,
|
||||||
hoistedNoteId: noteContext?.hoistedNoteId,
|
hoistedNoteId,
|
||||||
ntxId: noteContext?.ntxId,
|
ntxId: noteContext?.ntxId,
|
||||||
viewScope: noteContext?.viewScope,
|
viewScope: noteContext?.viewScope,
|
||||||
componentId: parentComponent.componentId,
|
componentId: parentComponent.componentId,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user