mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 02:45:54 +01:00
feat(react/note_title): bring back navigation title
This commit is contained in:
@@ -1,17 +1,36 @@
|
||||
import { useRef } from "preact/hooks";
|
||||
import { useEffect, useRef, useState } from "preact/hooks";
|
||||
import { t } from "../services/i18n";
|
||||
import FormTextBox from "./react/FormTextBox";
|
||||
import { useNoteContext, useNoteProperty, useSpacedUpdate } from "./react/hooks";
|
||||
import protected_session_holder from "../services/protected_session_holder";
|
||||
import server from "../services/server";
|
||||
import "./note_title.css";
|
||||
import { isLaunchBarConfig } from "../services/utils";
|
||||
|
||||
export default function NoteTitleWidget() {
|
||||
const { note, noteId, componentId } = useNoteContext();
|
||||
const title = useNoteProperty(note, "title", componentId);
|
||||
const { note, noteId, componentId, viewScope, noteContext } = useNoteContext();
|
||||
const title = useNoteProperty(note, "title", componentId);
|
||||
const isProtected = useNoteProperty(note, "isProtected");
|
||||
const newTitle = useRef("");
|
||||
|
||||
const [ isReadOnly, setReadOnly ] = useState<boolean>(false);
|
||||
const [ navigationTitle, setNavigationTitle ] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const isReadOnly = note === null
|
||||
|| note === undefined
|
||||
|| (note.isProtected && !protected_session_holder.isProtectedSessionAvailable())
|
||||
|| isLaunchBarConfig(note.noteId)
|
||||
|| viewScope?.viewMode !== "default";
|
||||
setReadOnly(isReadOnly);
|
||||
}, [ note?.noteId, note?.isProtected, viewScope?.viewMode ]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isReadOnly) {
|
||||
noteContext?.getNavigationTitle().then(setNavigationTitle);
|
||||
}
|
||||
}, [isReadOnly]);
|
||||
|
||||
const spacedUpdate = useSpacedUpdate(async () => {
|
||||
if (!note) {
|
||||
return;
|
||||
@@ -24,10 +43,11 @@ export default function NoteTitleWidget() {
|
||||
<div className="note-title-widget">
|
||||
<FormTextBox
|
||||
autocomplete="off"
|
||||
currentValue={title ?? ""}
|
||||
currentValue={(!isReadOnly ? title : navigationTitle) ?? ""}
|
||||
placeholder={t("note_title.placeholder")}
|
||||
className={`note-title ${isProtected ? "protected" : ""}`}
|
||||
tabIndex={100}
|
||||
readOnly={isReadOnly}
|
||||
onChange={(newValue) => {
|
||||
newTitle.current = newValue;
|
||||
spacedUpdate.scheduleUpdate();
|
||||
|
||||
Reference in New Issue
Block a user