2025-08-21 10:53:59 +03:00
|
|
|
import { useRef } from "preact/hooks";
|
2025-08-21 10:05:53 +03:00
|
|
|
import { t } from "../services/i18n";
|
|
|
|
|
import FormTextBox from "./react/FormTextBox";
|
2025-08-21 10:53:59 +03:00
|
|
|
import { useNoteContext, useNoteProperty, useSpacedUpdate } from "./react/hooks";
|
2025-08-21 10:05:53 +03:00
|
|
|
import protected_session_holder from "../services/protected_session_holder";
|
|
|
|
|
import server from "../services/server";
|
2025-08-21 10:34:30 +03:00
|
|
|
import "./note_title.css";
|
2025-08-20 23:53:13 +03:00
|
|
|
|
2025-08-20 21:50:06 +03:00
|
|
|
export default function NoteTitleWidget() {
|
2025-08-21 10:05:53 +03:00
|
|
|
const { note, noteId, componentId } = useNoteContext();
|
2025-08-21 10:53:59 +03:00
|
|
|
const title = useNoteProperty(note, "title", componentId);
|
2025-08-21 10:44:58 +03:00
|
|
|
const isProtected = useNoteProperty(note, "isProtected");
|
2025-08-21 10:53:59 +03:00
|
|
|
const newTitle = useRef("");
|
2025-08-21 10:05:53 +03:00
|
|
|
|
|
|
|
|
const spacedUpdate = useSpacedUpdate(async () => {
|
|
|
|
|
if (!note) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
protected_session_holder.touchProtectedSessionIfNecessary(note);
|
2025-08-21 10:53:59 +03:00
|
|
|
await server.put<void>(`notes/${noteId}/title`, { title: newTitle.current }, componentId);
|
2025-08-21 10:05:53 +03:00
|
|
|
});
|
|
|
|
|
|
2025-08-20 21:50:06 +03:00
|
|
|
return (
|
2025-08-21 10:34:30 +03:00
|
|
|
<div className="note-title-widget">
|
2025-08-21 10:05:53 +03:00
|
|
|
<FormTextBox
|
|
|
|
|
autocomplete="off"
|
2025-08-21 10:53:59 +03:00
|
|
|
currentValue={title ?? ""}
|
2025-08-21 10:05:53 +03:00
|
|
|
placeholder={t("note_title.placeholder")}
|
2025-08-21 10:34:30 +03:00
|
|
|
className={`note-title ${isProtected ? "protected" : ""}`}
|
2025-08-21 10:05:53 +03:00
|
|
|
tabIndex={100}
|
|
|
|
|
onChange={(newValue) => {
|
2025-08-21 10:53:59 +03:00
|
|
|
newTitle.current = newValue;
|
2025-08-21 10:05:53 +03:00
|
|
|
spacedUpdate.scheduleUpdate();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2025-08-21 10:34:30 +03:00
|
|
|
</div>
|
2025-08-20 21:50:06 +03:00
|
|
|
);
|
|
|
|
|
}
|