web: use default note title from settings

This commit is contained in:
Abdullah Atta
2023-06-03 21:37:57 +05:00
committed by Abdullah Atta
parent 7f5d5fcb82
commit 58ba453f57

View File

@@ -43,22 +43,29 @@ function TitleBox(props: TitleBoxProps) {
return isMobile || isTablet ? 1.625 : 2.625;
}, [isMobile, isTablet]);
const updateFontSize = useCallback(() => {
if (!inputRef.current) return;
const fontSize = textLengthToFontSize(
inputRef.current.value.length,
MAX_FONT_SIZE
);
inputRef.current.style.fontSize = `${fontSize}em`;
}, [MAX_FONT_SIZE]);
const updateFontSize = useCallback(
(length) => {
if (!inputRef.current) return;
const fontSize = textLengthToFontSize(length, MAX_FONT_SIZE);
inputRef.current.style.fontSize = `${fontSize}em`;
},
[MAX_FONT_SIZE]
);
useEffect(() => {
if (inputRef.current) {
inputRef.current.placeholder = "Note title";
inputRef.current.value = title;
updateFontSize();
updateFontSize(title.length);
}
}, [id, updateFontSize]);
useEffect(() => {
if (inputRef.current && inputRef.current.value !== title) {
inputRef.current.placeholder = title || "Note title";
}
}, [title]);
return (
<Input
ref={inputRef}
@@ -77,7 +84,7 @@ function TitleBox(props: TitleBoxProps) {
onChange={(e) => {
const { sessionId, id } = store.get().session;
debouncedOnTitleChange(sessionId, id, e.target.value);
updateFontSize();
updateFontSize(e.target.value.length);
}}
/>
);
@@ -88,7 +95,6 @@ export default React.memo(TitleBox, (prevProps, nextProps) => {
});
function onTitleChange(noteId: string, title: string) {
if (!title) return;
store.get().setTitle(noteId, title);
}