Skip to content

Commit b4fb9f1

Browse files
[WEB-495] chore: issue title improvement (#3780)
* chore: trim issue title * chore: issue title improvement
1 parent 31ebecb commit b4fb9f1

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

web/components/issues/title-input.tsx

+28-2
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,52 @@ export type IssueTitleInputProps = {
1919
};
2020

2121
export const IssueTitleInput: FC<IssueTitleInputProps> = observer((props) => {
22-
const { disabled, value, workspaceSlug, setIsSubmitting, issueId, issueOperations, projectId } = props;
22+
const { disabled, value, workspaceSlug, isSubmitting, setIsSubmitting, issueId, issueOperations, projectId } = props;
2323
// states
2424
const [title, setTitle] = useState("");
2525
// hooks
26-
2726
const debouncedValue = useDebounce(title, 1500);
2827

2928
useEffect(() => {
3029
if (value) setTitle(value);
3130
}, [value]);
3231

3332
useEffect(() => {
33+
const textarea = document.querySelector("#title-input");
3434
if (debouncedValue && debouncedValue !== value) {
3535
issueOperations.update(workspaceSlug, projectId, issueId, { name: debouncedValue }, false).finally(() => {
3636
setIsSubmitting("saved");
37+
if (textarea && !textarea.matches(":focus")) {
38+
const trimmedTitle = debouncedValue.trim();
39+
if (trimmedTitle !== title) setTitle(trimmedTitle);
40+
}
3741
});
3842
}
3943
// DO NOT Add more dependencies here. It will cause multiple requests to be sent.
4044
// eslint-disable-next-line react-hooks/exhaustive-deps
4145
}, [debouncedValue]);
4246

47+
useEffect(() => {
48+
const handleBlur = () => {
49+
const trimmedTitle = title.trim();
50+
if (trimmedTitle !== title && isSubmitting !== "submitting") {
51+
setTitle(trimmedTitle);
52+
setIsSubmitting("submitting");
53+
}
54+
};
55+
56+
const textarea = document.querySelector("#title-input"); // You might need to change this selector according to your TextArea component
57+
if (textarea) {
58+
textarea.addEventListener("blur", handleBlur);
59+
}
60+
61+
return () => {
62+
if (textarea) {
63+
textarea.removeEventListener("blur", handleBlur);
64+
}
65+
};
66+
}, [title, isSubmitting, setIsSubmitting]);
67+
4368
const handleTitleChange = useCallback(
4469
(e: React.ChangeEvent<HTMLTextAreaElement>) => {
4570
setIsSubmitting("submitting");
@@ -53,6 +78,7 @@ export const IssueTitleInput: FC<IssueTitleInputProps> = observer((props) => {
5378
return (
5479
<div className="relative">
5580
<TextArea
81+
id="title-input"
5682
className={`min-h-min block w-full resize-none overflow-hidden rounded border-none bg-transparent px-3 py-2 text-2xl font-medium outline-none ring-0 focus:ring-1 focus:ring-custom-primary ${
5783
title?.length === 0 ? "!ring-red-400" : ""
5884
}`}

0 commit comments

Comments
 (0)