2025-08-21 10:05:53 +03:00
|
|
|
import { useEffect, useRef, useState } from "preact/hooks";
|
|
|
|
|
import { t } from "../services/i18n";
|
|
|
|
|
import FormTextBox from "./react/FormTextBox";
|
|
|
|
|
import { useNoteContext, useSpacedUpdate } from "./react/hooks";
|
|
|
|
|
import protected_session_holder from "../services/protected_session_holder";
|
|
|
|
|
import server from "../services/server";
|
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();
|
|
|
|
|
const [ title, setTitle ] = useState(note?.title);
|
|
|
|
|
useEffect(() => setTitle(note?.title), [ note?.title ]);
|
|
|
|
|
|
|
|
|
|
const spacedUpdate = useSpacedUpdate(async () => {
|
|
|
|
|
if (!note) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
protected_session_holder.touchProtectedSessionIfNecessary(note);
|
|
|
|
|
await server.put<void>(`notes/${noteId}/title`, { title: title }, componentId);
|
|
|
|
|
});
|
|
|
|
|
|
2025-08-20 21:50:06 +03:00
|
|
|
return (
|
|
|
|
|
<>
|
2025-08-21 10:05:53 +03:00
|
|
|
<FormTextBox
|
|
|
|
|
autocomplete="off"
|
|
|
|
|
currentValue={title}
|
|
|
|
|
placeholder={t("note_title.placeholder")}
|
|
|
|
|
className="note-title"
|
|
|
|
|
tabIndex={100}
|
|
|
|
|
onChange={(newValue) => {
|
|
|
|
|
setTitle(newValue);
|
|
|
|
|
spacedUpdate.scheduleUpdate();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2025-08-20 21:50:06 +03:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|