mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 19:05:59 +01:00
feat(react/note_title): bring back navigation title
This commit is contained in:
@@ -740,7 +740,7 @@ function isUpdateAvailable(latestVersion: string | null | undefined, currentVers
|
|||||||
return compareVersions(latestVersion, currentVersion) > 0;
|
return compareVersions(latestVersion, currentVersion) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isLaunchBarConfig(noteId: string) {
|
export function isLaunchBarConfig(noteId: string) {
|
||||||
return ["_lbRoot", "_lbAvailableLaunchers", "_lbVisibleLaunchers", "_lbMobileRoot", "_lbMobileAvailableLaunchers", "_lbMobileVisibleLaunchers"].includes(noteId);
|
return ["_lbRoot", "_lbAvailableLaunchers", "_lbVisibleLaunchers", "_lbMobileRoot", "_lbMobileAvailableLaunchers", "_lbMobileVisibleLaunchers"].includes(noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,18 +46,6 @@ export default class NoteTitleWidget extends NoteContextAwareWidget {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshWithNote(note: FNote) {
|
|
||||||
const isReadOnly =
|
|
||||||
(note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable())
|
|
||||||
|| utils.isLaunchBarConfig(note.noteId)
|
|
||||||
|| this.noteContext?.viewScope?.viewMode !== "default";
|
|
||||||
|
|
||||||
this.$noteTitle.val(isReadOnly ? (await this.noteContext?.getNavigationTitle()) || "" : note.title);
|
|
||||||
this.$noteTitle.prop("readonly", isReadOnly);
|
|
||||||
|
|
||||||
this.setProtectedStatus(note);
|
|
||||||
}
|
|
||||||
|
|
||||||
async beforeNoteSwitchEvent({ noteContext }: EventData<"beforeNoteSwitch">) {
|
async beforeNoteSwitchEvent({ noteContext }: EventData<"beforeNoteSwitch">) {
|
||||||
if (this.isNoteContext(noteContext.ntxId)) {
|
if (this.isNoteContext(noteContext.ntxId)) {
|
||||||
await this.spacedUpdate.updateNowIfNecessary();
|
await this.spacedUpdate.updateNowIfNecessary();
|
||||||
|
|||||||
@@ -1,17 +1,36 @@
|
|||||||
import { useRef } from "preact/hooks";
|
import { useEffect, useRef, useState } from "preact/hooks";
|
||||||
import { t } from "../services/i18n";
|
import { t } from "../services/i18n";
|
||||||
import FormTextBox from "./react/FormTextBox";
|
import FormTextBox from "./react/FormTextBox";
|
||||||
import { useNoteContext, useNoteProperty, useSpacedUpdate } from "./react/hooks";
|
import { useNoteContext, useNoteProperty, useSpacedUpdate } from "./react/hooks";
|
||||||
import protected_session_holder from "../services/protected_session_holder";
|
import protected_session_holder from "../services/protected_session_holder";
|
||||||
import server from "../services/server";
|
import server from "../services/server";
|
||||||
import "./note_title.css";
|
import "./note_title.css";
|
||||||
|
import { isLaunchBarConfig } from "../services/utils";
|
||||||
|
|
||||||
export default function NoteTitleWidget() {
|
export default function NoteTitleWidget() {
|
||||||
const { note, noteId, componentId } = useNoteContext();
|
const { note, noteId, componentId, viewScope, noteContext } = useNoteContext();
|
||||||
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 [ 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 () => {
|
const spacedUpdate = useSpacedUpdate(async () => {
|
||||||
if (!note) {
|
if (!note) {
|
||||||
return;
|
return;
|
||||||
@@ -24,10 +43,11 @@ export default function NoteTitleWidget() {
|
|||||||
<div className="note-title-widget">
|
<div className="note-title-widget">
|
||||||
<FormTextBox
|
<FormTextBox
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
currentValue={title ?? ""}
|
currentValue={(!isReadOnly ? title : navigationTitle) ?? ""}
|
||||||
placeholder={t("note_title.placeholder")}
|
placeholder={t("note_title.placeholder")}
|
||||||
className={`note-title ${isProtected ? "protected" : ""}`}
|
className={`note-title ${isProtected ? "protected" : ""}`}
|
||||||
tabIndex={100}
|
tabIndex={100}
|
||||||
|
readOnly={isReadOnly}
|
||||||
onChange={(newValue) => {
|
onChange={(newValue) => {
|
||||||
newTitle.current = newValue;
|
newTitle.current = newValue;
|
||||||
spacedUpdate.scheduleUpdate();
|
spacedUpdate.scheduleUpdate();
|
||||||
|
|||||||
@@ -259,7 +259,9 @@ export function useNoteContext() {
|
|||||||
notePath: noteContext?.notePath,
|
notePath: noteContext?.notePath,
|
||||||
hoistedNoteId: noteContext?.hoistedNoteId,
|
hoistedNoteId: noteContext?.hoistedNoteId,
|
||||||
ntxId: noteContext?.ntxId,
|
ntxId: noteContext?.ntxId,
|
||||||
componentId: parentComponent.componentId
|
viewScope: noteContext?.viewScope,
|
||||||
|
componentId: parentComponent.componentId,
|
||||||
|
noteContext: noteContext
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -288,6 +290,6 @@ export function useNoteProperty<T extends keyof FNote>(note: FNote | null | unde
|
|||||||
setValue(note[property]);
|
setValue(note[property]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user