mirror of
https://github.com/zadam/trilium.git
synced 2025-10-31 18:36:30 +01:00
refactor(react/note_title): use hook for listening to note property
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useRef, useState } from "preact/hooks";
|
||||
import { t } from "../services/i18n";
|
||||
import FormTextBox from "./react/FormTextBox";
|
||||
import { useNoteContext, useSpacedUpdate, useTriliumEventBeta } from "./react/hooks";
|
||||
import { useNoteContext, useNoteProperty, useSpacedUpdate, useTriliumEventBeta } from "./react/hooks";
|
||||
import protected_session_holder from "../services/protected_session_holder";
|
||||
import server from "../services/server";
|
||||
import "./note_title.css";
|
||||
@@ -9,9 +9,8 @@ import "./note_title.css";
|
||||
export default function NoteTitleWidget() {
|
||||
const { note, noteId, componentId } = useNoteContext();
|
||||
const [ title, setTitle ] = useState(note?.title);
|
||||
const [ isProtected, setProtected ] = useState(note?.isProtected);
|
||||
const isProtected = useNoteProperty(note, "isProtected");
|
||||
useEffect(() => setTitle(note?.title), [ note?.noteId ]);
|
||||
useEffect(() => setProtected(note?.isProtected), [ note?.isProtected ]);
|
||||
|
||||
const spacedUpdate = useSpacedUpdate(async () => {
|
||||
if (!note) {
|
||||
@@ -21,10 +20,7 @@ export default function NoteTitleWidget() {
|
||||
await server.put<void>(`notes/${noteId}/title`, { title: title }, componentId);
|
||||
});
|
||||
|
||||
useTriliumEventBeta("entitiesReloaded", ({ loadResults }) => {
|
||||
if (loadResults.isNoteReloaded(noteId) && note) {
|
||||
setProtected(note.isProtected);
|
||||
}
|
||||
useTriliumEventBeta("entitiesReloaded", ({ loadResults }) => {
|
||||
if (loadResults.isNoteReloaded(noteId, componentId)) {
|
||||
setTitle(note?.title);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user