11import {
2- Body1Strong ,
3- Button ,
4- Caption1 ,
5- Title2 ,
2+ Body1Strong ,
3+ Button ,
4+ Caption1 ,
5+ Title2 ,
66} from "@fluentui/react-components" ;
7- import { Send20Regular } from "@fluentui/react-icons" ;
87import React , { useRef , useEffect , useState } from "react" ;
98import { useNavigate , useLocation } from "react-router-dom" ;
109
@@ -22,133 +21,133 @@ import PromptCard from "@/coral/components/PromptCard";
2221import { Send } from "@/coral/imports/bundleicons" ;
2322
2423const HomeInput : React . FC < HomeInputProps > = ( {
25- onInputSubmit,
26- onQuickTaskSelect,
24+ onInputSubmit,
25+ onQuickTaskSelect,
2726} ) => {
28- const [ submitting , setSubmitting ] = useState ( false ) ;
29- const [ input , setInput ] = useState ( "" ) ;
30-
31- const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
32- const navigate = useNavigate ( ) ;
33- const location = useLocation ( ) ; // ✅ location.state used to control focus
34- const { showToast, dismissToast } = useInlineToaster ( ) ;
35-
36- useEffect ( ( ) => {
37- if ( location . state ?. focusInput ) {
38- textareaRef . current ?. focus ( ) ;
39- }
40- } , [ location ] ) ;
41-
42- const resetTextarea = ( ) => {
43- setInput ( "" ) ;
44- if ( textareaRef . current ) {
45- textareaRef . current . style . height = "auto" ;
46- textareaRef . current . focus ( ) ;
47- }
48- } ;
49-
50- useEffect ( ( ) => {
51- const cleanup = NewTaskService . addResetListener ( resetTextarea ) ;
52- return cleanup ;
53- } , [ ] ) ;
54-
55- const handleSubmit = async ( ) => {
56- if ( input . trim ( ) ) {
57- setSubmitting ( true ) ;
58- let id = showToast ( "Creating a plan" , "progress" ) ;
59-
60- try {
61- const response = await TaskService . submitInputTask ( input . trim ( ) ) ;
62- setInput ( "" ) ;
27+ const [ submitting , setSubmitting ] = useState ( false ) ;
28+ const [ input , setInput ] = useState ( "" ) ;
29+
30+ const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
31+ const navigate = useNavigate ( ) ;
32+ const location = useLocation ( ) ; // ✅ location.state used to control focus
33+ const { showToast, dismissToast } = useInlineToaster ( ) ;
34+
35+ useEffect ( ( ) => {
36+ if ( location . state ?. focusInput ) {
37+ textareaRef . current ?. focus ( ) ;
38+ }
39+ } , [ location ] ) ;
6340
41+ const resetTextarea = ( ) => {
42+ setInput ( "" ) ;
6443 if ( textareaRef . current ) {
65- textareaRef . current . style . height = "auto" ;
44+ textareaRef . current . style . height = "auto" ;
45+ textareaRef . current . focus ( ) ;
46+ }
47+ } ;
48+
49+ useEffect ( ( ) => {
50+ const cleanup = NewTaskService . addResetListener ( resetTextarea ) ;
51+ return cleanup ;
52+ } , [ ] ) ;
53+
54+ const handleSubmit = async ( ) => {
55+ if ( input . trim ( ) ) {
56+ setSubmitting ( true ) ;
57+ let id = showToast ( "Creating a plan" , "progress" ) ;
58+
59+ try {
60+ const response = await TaskService . submitInputTask ( input . trim ( ) ) ;
61+ setInput ( "" ) ;
62+
63+ if ( textareaRef . current ) {
64+ textareaRef . current . style . height = "auto" ;
65+ }
66+
67+ if ( response . plan_id && response . plan_id !== null ) {
68+ showToast ( "Plan created!" , "success" ) ;
69+ dismissToast ( id ) ;
70+ navigate ( `/plan/${ response . plan_id } ` ) ;
71+ } else {
72+ console . log ( "Invalid plan:" , response . status ) ;
73+ showToast ( "Failed to create plan" , "error" ) ;
74+ dismissToast ( id ) ;
75+ }
76+ } catch ( error ) {
77+ console . error ( "Failed to create plan:" , error ) ;
78+ dismissToast ( id ) ;
79+ showToast ( "Something went wrong" , "error" ) ;
80+ } finally {
81+ setInput ( "" ) ;
82+ setSubmitting ( false ) ;
83+ }
6684 }
85+ } ;
6786
68- if ( response . plan_id && response . plan_id !== null ) {
69- showToast ( "Plan created!" , "success" ) ;
70- dismissToast ( id ) ;
71- navigate ( `/plan/${ response . plan_id } ` ) ;
72- } else {
73- console . log ( "Invalid plan:" , response . status ) ;
74- showToast ( "Failed to create plan" , "error" ) ;
75- dismissToast ( id ) ;
87+ const handleQuickTaskClick = ( task : QuickTask ) => {
88+ setInput ( task . description ) ;
89+ if ( textareaRef . current ) {
90+ textareaRef . current . focus ( ) ;
7691 }
77- } catch ( error ) {
78- console . error ( "Failed to create plan:" , error ) ;
79- dismissToast ( id ) ;
80- showToast ( "Something went wrong" , "error" ) ;
81- } finally {
82- setInput ( "" ) ;
83- setSubmitting ( false ) ;
84- }
85- }
86- } ;
87-
88- const handleQuickTaskClick = ( task : QuickTask ) => {
89- setInput ( task . description ) ;
90- if ( textareaRef . current ) {
91- textareaRef . current . focus ( ) ;
92- }
93- onQuickTaskSelect ( task . description ) ;
94- } ;
95-
96- useEffect ( ( ) => {
97- if ( textareaRef . current ) {
98- textareaRef . current . style . height = "auto" ;
99- textareaRef . current . style . height = `${ textareaRef . current . scrollHeight } px` ;
100- }
101- } , [ input ] ) ;
102-
103- return (
104- < div className = "home-input-container" >
105- < div className = "home-input-content" >
106- < div className = "home-input-center-content" >
107- < div className = "home-input-title-wrapper" >
108- < Title2 > How can I help?</ Title2 >
109- </ div >
110-
111- < ChatInput
112- ref = { textareaRef } // forwarding
113- value = { input }
114- placeholder = "Tell us what needs planning, building, or connecting—we'll handle the rest."
115- onChange = { setInput }
116- onEnter = { handleSubmit }
117- disabledChat = { submitting }
118- >
119- < Button
120- appearance = "subtle"
121- className = "home-input-send-button"
122- onClick = { handleSubmit }
123- disabled = { submitting }
124- icon = { < Send /> }
125- />
126- </ ChatInput >
127-
128- < InlineToaster />
129-
130- < div className = "home-input-quick-tasks-section" >
131- < div className = "home-input-quick-tasks-header" >
132- < Body1Strong > Quick tasks</ Body1Strong >
133- </ div >
92+ onQuickTaskSelect ( task . description ) ;
93+ } ;
13494
135- < div className = "home-input-quick-tasks" >
136- { quickTasks . map ( ( task ) => (
137- < PromptCard
138- key = { task . id }
139- title = { task . title }
140- icon = { task . icon }
141- description = { task . description }
142- onClick = { ( ) => handleQuickTaskClick ( task ) }
143- disabled = { submitting }
144- />
145- ) ) }
95+ useEffect ( ( ) => {
96+ if ( textareaRef . current ) {
97+ textareaRef . current . style . height = "auto" ;
98+ textareaRef . current . style . height = `${ textareaRef . current . scrollHeight } px` ;
99+ }
100+ } , [ input ] ) ;
101+
102+ return (
103+ < div className = "home-input-container" >
104+ < div className = "home-input-content" >
105+ < div className = "home-input-center-content" >
106+ < div className = "home-input-title-wrapper" >
107+ < Title2 > How can I help?</ Title2 >
108+ </ div >
109+
110+ < ChatInput
111+ ref = { textareaRef } // forwarding
112+ value = { input }
113+ placeholder = "Tell us what needs planning, building, or connecting—we'll handle the rest."
114+ onChange = { setInput }
115+ onEnter = { handleSubmit }
116+ disabledChat = { submitting }
117+ >
118+ < Button
119+ appearance = "subtle"
120+ className = "home-input-send-button"
121+ onClick = { handleSubmit }
122+ disabled = { submitting }
123+ icon = { < Send /> }
124+ />
125+ </ ChatInput >
126+
127+ < InlineToaster />
128+
129+ < div className = "home-input-quick-tasks-section" >
130+ < div className = "home-input-quick-tasks-header" >
131+ < Body1Strong > Quick tasks</ Body1Strong >
132+ </ div >
133+
134+ < div className = "home-input-quick-tasks" >
135+ { quickTasks . map ( ( task ) => (
136+ < PromptCard
137+ key = { task . id }
138+ title = { task . title }
139+ icon = { task . icon }
140+ description = { task . description }
141+ onClick = { ( ) => handleQuickTaskClick ( task ) }
142+ disabled = { submitting }
143+ />
144+ ) ) }
145+ </ div >
146+ </ div >
147+ </ div >
146148 </ div >
147- </ div >
148149 </ div >
149- </ div >
150- </ div >
151- ) ;
150+ ) ;
152151} ;
153152
154153export default HomeInput ;
0 commit comments