fix: updating title placeholder on save note

This commit is contained in:
Ammar Ahmed
2022-07-08 23:52:45 +05:00
parent 989bd9474e
commit fa35ba9190
3 changed files with 12 additions and 1 deletions

View File

@@ -118,6 +118,7 @@ const Tiptap = () => {
const update = () => { const update = () => {
setTick((tick) => tick + 1); setTick((tick) => tick + 1);
setLayout(false); setLayout(false);
controller.setTitlePlaceholder("Note title");
setImmediate(() => setLayout(true)); setImmediate(() => setLayout(true));
}; };
@@ -167,6 +168,7 @@ const Tiptap = () => {
<> <>
<Tags /> <Tags />
<Title <Title
titlePlaceholder={controller.titlePlaceholder}
readonly={settings.readonly} readonly={settings.readonly}
controller={controllerRef} controller={controllerRef}
title={controller.title} title={controller.title}

View File

@@ -5,10 +5,12 @@ import styles from "./styles.module.css";
function Title({ function Title({
controller, controller,
title, title,
titlePlaceholder,
readonly, readonly,
}: { }: {
controller: RefObject<EditorController>; controller: RefObject<EditorController>;
title: string; title: string;
titlePlaceholder: string;
readonly: boolean; readonly: boolean;
}) { }) {
const titleRef = useRef<HTMLInputElement>(null); const titleRef = useRef<HTMLInputElement>(null);
@@ -46,13 +48,14 @@ function Title({
if (!emitUpdate.current) return; if (!emitUpdate.current) return;
controller.current?.titleChange(event.target.value); controller.current?.titleChange(event.target.value);
}} }}
placeholder="Note title" placeholder={titlePlaceholder}
/> />
); );
} }
export default React.memo(Title, (prev, next) => { export default React.memo(Title, (prev, next) => {
if (prev.title !== next.title) return false; if (prev.title !== next.title) return false;
if (prev.titlePlaceholder !== next.titlePlaceholder) return false;
if (prev.readonly !== next.readonly) return false; if (prev.readonly !== next.readonly) return false;
return true; return true;
}); });

View File

@@ -43,6 +43,8 @@ export type EditorController = {
downloadAttachment: (attachment: Attachment) => void; downloadAttachment: (attachment: Attachment) => void;
content: MutableRefObject<string | null>; content: MutableRefObject<string | null>;
onUpdate: () => void; onUpdate: () => void;
titlePlaceholder: string;
setTitlePlaceholder: React.Dispatch<React.SetStateAction<string>>;
}; };
export function useEditorController( export function useEditorController(
@@ -50,6 +52,7 @@ export function useEditorController(
update: () => void update: () => void
): EditorController { ): EditorController {
const [title, setTitle] = useState(""); const [title, setTitle] = useState("");
const [titlePlaceholder, setTitlePlaceholder] = useState("Note title");
const htmlContentRef = useRef<string | null>(null); const htmlContentRef = useRef<string | null>(null);
const timers = useRef<Timers>({ const timers = useRef<Timers>({
selectionChange: null, selectionChange: null,
@@ -141,6 +144,7 @@ export function useEditorController(
setTitle(value); setTitle(value);
break; break;
case "native:titleplaceholder": case "native:titleplaceholder":
setTitlePlaceholder(value);
break; break;
case "native:status": case "native:status":
break; break;
@@ -191,6 +195,8 @@ export function useEditorController(
scroll, scroll,
title, title,
setTitle, setTitle,
titlePlaceholder,
setTitlePlaceholder,
openFilePicker, openFilePicker,
downloadAttachment, downloadAttachment,
content: htmlContentRef, content: htmlContentRef,