mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 03:59:05 +01:00
fix(react/note_title): not refreshing on protected session
This commit is contained in:
parent
be576176c5
commit
033e90f8b7
@ -12,10 +12,10 @@ export default function NoteTitleWidget() {
|
|||||||
const title = useNoteProperty(note, "title", componentId);
|
const title = useNoteProperty(note, "title", componentId);
|
||||||
const isProtected = useNoteProperty(note, "isProtected");
|
const isProtected = useNoteProperty(note, "isProtected");
|
||||||
const newTitle = useRef("");
|
const newTitle = useRef("");
|
||||||
|
|
||||||
const [ isReadOnly, setReadOnly ] = useState<boolean>(false);
|
const [ isReadOnly, setReadOnly ] = useState<boolean>(false);
|
||||||
const [ navigationTitle, setNavigationTitle ] = useState<string | null>(null);
|
const [ navigationTitle, setNavigationTitle ] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const isReadOnly = note === null
|
const isReadOnly = note === null
|
||||||
|| note === undefined
|
|| note === undefined
|
||||||
@ -23,7 +23,7 @@ export default function NoteTitleWidget() {
|
|||||||
|| isLaunchBarConfig(note.noteId)
|
|| isLaunchBarConfig(note.noteId)
|
||||||
|| viewScope?.viewMode !== "default";
|
|| viewScope?.viewMode !== "default";
|
||||||
setReadOnly(isReadOnly);
|
setReadOnly(isReadOnly);
|
||||||
}, [ note?.noteId, note?.isProtected, viewScope?.viewMode ]);
|
}, [ note, note?.noteId, note?.isProtected, viewScope?.viewMode ]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isReadOnly) {
|
if (isReadOnly) {
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import Component from "../../components/component";
|
|||||||
import NoteContext from "../../components/note_context";
|
import NoteContext from "../../components/note_context";
|
||||||
import { ReactWrappedWidget } from "../basic_widget";
|
import { ReactWrappedWidget } from "../basic_widget";
|
||||||
import FNote from "../../entities/fnote";
|
import FNote from "../../entities/fnote";
|
||||||
|
import froca from "../../services/froca";
|
||||||
|
|
||||||
type TriliumEventHandler<T extends EventNames> = (data: EventData<T>) => void;
|
type TriliumEventHandler<T extends EventNames> = (data: EventData<T>) => void;
|
||||||
const registeredHandlers: Map<Component, Map<EventNames, TriliumEventHandler<any>[]>> = new Map();
|
const registeredHandlers: Map<Component, Map<EventNames, TriliumEventHandler<any>[]>> = new Map();
|
||||||
@ -233,10 +234,15 @@ export function useNoteContext() {
|
|||||||
|
|
||||||
const [ noteContext, setNoteContext ] = useState<NoteContext>();
|
const [ noteContext, setNoteContext ] = useState<NoteContext>();
|
||||||
const [ notePath, setNotePath ] = useState<string | null | undefined>();
|
const [ notePath, setNotePath ] = useState<string | null | undefined>();
|
||||||
|
const [ note, setNote ] = useState<FNote | null | undefined>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setNote(noteContext?.note);
|
||||||
|
}, [ notePath ]);
|
||||||
|
|
||||||
useTriliumEventBeta("activeContextChanged", ({ noteContext }) => {
|
useTriliumEventBeta("activeContextChanged", ({ noteContext }) => {
|
||||||
setNoteContext(noteContext);
|
setNoteContext(noteContext);
|
||||||
setNotePath(noteContext.notePath);
|
setNotePath(noteContext.notePath);
|
||||||
});
|
});
|
||||||
useTriliumEventBeta("setNoteContext", ({ noteContext }) => {
|
useTriliumEventBeta("setNoteContext", ({ noteContext }) => {
|
||||||
console.log("Set note context", noteContext, noteContext.noteId);
|
console.log("Set note context", noteContext, noteContext.noteId);
|
||||||
@ -250,11 +256,14 @@ export function useNoteContext() {
|
|||||||
console.warn("Note switched", notePath);
|
console.warn("Note switched", notePath);
|
||||||
setNotePath(notePath);
|
setNotePath(notePath);
|
||||||
});
|
});
|
||||||
|
useTriliumEventBeta("frocaReloaded", () => {
|
||||||
|
setNote(noteContext?.note);
|
||||||
|
});
|
||||||
|
|
||||||
const parentComponent = useContext(ParentComponent) as ReactWrappedWidget;
|
const parentComponent = useContext(ParentComponent) as ReactWrappedWidget;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
note: noteContext?.note,
|
note: note,
|
||||||
noteId: noteContext?.note?.noteId,
|
noteId: noteContext?.note?.noteId,
|
||||||
notePath: noteContext?.notePath,
|
notePath: noteContext?.notePath,
|
||||||
hoistedNoteId: noteContext?.hoistedNoteId,
|
hoistedNoteId: noteContext?.hoistedNoteId,
|
||||||
@ -280,16 +289,17 @@ export function useNoteProperty<T extends keyof FNote>(note: FNote | null | unde
|
|||||||
}
|
}
|
||||||
|
|
||||||
const [ value, setValue ] = useState<FNote[T]>(note[property]);
|
const [ value, setValue ] = useState<FNote[T]>(note[property]);
|
||||||
|
const refreshValue = () => setValue(note[property]);
|
||||||
|
|
||||||
// Watch for note changes.
|
// Watch for note changes.
|
||||||
useEffect(() => setValue(note[property]), [ note[property] ]);
|
useEffect(() => refreshValue(), [ note, note[property] ]);
|
||||||
|
|
||||||
// Watch for external changes.
|
// Watch for external changes.
|
||||||
useTriliumEventBeta("entitiesReloaded", ({ loadResults }) => {
|
useTriliumEventBeta("entitiesReloaded", ({ loadResults }) => {
|
||||||
if (loadResults.isNoteReloaded(note.noteId, componentId)) {
|
if (loadResults.isNoteReloaded(note.noteId, componentId)) {
|
||||||
setValue(note[property]);
|
refreshValue();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return value;
|
return note[property];
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user