@@ -19,27 +19,52 @@ export type IssueTitleInputProps = {
19
19
} ;
20
20
21
21
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 ;
23
23
// states
24
24
const [ title , setTitle ] = useState ( "" ) ;
25
25
// hooks
26
-
27
26
const debouncedValue = useDebounce ( title , 1500 ) ;
28
27
29
28
useEffect ( ( ) => {
30
29
if ( value ) setTitle ( value ) ;
31
30
} , [ value ] ) ;
32
31
33
32
useEffect ( ( ) => {
33
+ const textarea = document . querySelector ( "#title-input" ) ;
34
34
if ( debouncedValue && debouncedValue !== value ) {
35
35
issueOperations . update ( workspaceSlug , projectId , issueId , { name : debouncedValue } , false ) . finally ( ( ) => {
36
36
setIsSubmitting ( "saved" ) ;
37
+ if ( textarea && ! textarea . matches ( ":focus" ) ) {
38
+ const trimmedTitle = debouncedValue . trim ( ) ;
39
+ if ( trimmedTitle !== title ) setTitle ( trimmedTitle ) ;
40
+ }
37
41
} ) ;
38
42
}
39
43
// DO NOT Add more dependencies here. It will cause multiple requests to be sent.
40
44
// eslint-disable-next-line react-hooks/exhaustive-deps
41
45
} , [ debouncedValue ] ) ;
42
46
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
+
43
68
const handleTitleChange = useCallback (
44
69
( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
45
70
setIsSubmitting ( "submitting" ) ;
@@ -53,6 +78,7 @@ export const IssueTitleInput: FC<IssueTitleInputProps> = observer((props) => {
53
78
return (
54
79
< div className = "relative" >
55
80
< TextArea
81
+ id = "title-input"
56
82
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 ${
57
83
title ?. length === 0 ? "!ring-red-400" : ""
58
84
} `}
0 commit comments