1-
21import {
3- Body1 ,
4- Body1Strong ,
5- Button ,
6- Caption1 ,
7- Card ,
8- Text ,
9- Title2 ,
2+ Body1 ,
3+ Body1Strong ,
4+ Button ,
5+ Caption1 ,
6+ Card ,
7+ Title2 ,
108} from "@fluentui/react-components" ;
11- import {
12- Send20Regular ,
13- } from "@fluentui/react-icons" ;
9+ import { FoodToast20Regular , Send20Regular } from "@fluentui/react-icons" ;
1410import React , { useRef , useEffect , useState } from "react" ;
15- import { useNavigate } from ' react-router-dom' ;
11+ import { useNavigate } from " react-router-dom" ;
1612import "./../../styles/HomeInput.css" ;
1713import "./../../styles/Chat.css" ;
18- import "../../styles/prism-material-oceanic.css"
14+ import "../../styles/prism-material-oceanic.css" ;
1915import { HomeInputProps , quickTasks , QuickTask } from "../../models/homeInput" ;
2016import { TaskService } from "../../services/TaskService" ;
2117import { NewTaskService } from "../../services/NewTaskService" ;
2218import ChatInput from "@/coral/modules/ChatInput" ;
23-
19+ import InlineToaster , { useInlineToaster } from "../toast/InlineToaster" ;
2420
2521const HomeInput : React . FC < HomeInputProps > = ( {
26- onInputSubmit,
27- onQuickTaskSelect,
22+ onInputSubmit,
23+ onQuickTaskSelect,
2824} ) => {
29- const [ input , setInput ] = useState ( "" ) ;
30- const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
31- const navigate = useNavigate ( ) ;
25+ const [ input , setInput ] = useState ( "" ) ;
26+ const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
27+ const navigate = useNavigate ( ) ;
28+ const { showToast } = useInlineToaster ( ) ;
29+
30+ const resetTextarea = ( ) => {
31+ setInput ( "" ) ;
32+ if ( textareaRef . current ) {
33+ textareaRef . current . style . height = "auto" ;
34+ textareaRef . current . focus ( ) ;
35+ }
36+ } ;
37+
38+ useEffect ( ( ) => {
39+ const cleanup = NewTaskService . addResetListener ( resetTextarea ) ;
40+ return cleanup ;
41+ } , [ ] ) ;
42+
43+ const handleSubmit = async ( ) => {
44+ if ( input . trim ( ) ) {
45+ try {
46+ const response = await TaskService . submitInputTask ( input . trim ( ) ) ;
3247
33- /**
34- * Reset textarea to empty state
35- */
36- const resetTextarea = ( ) => {
3748 setInput ( "" ) ;
3849 if ( textareaRef . current ) {
39- textareaRef . current . style . height = "auto" ;
40- textareaRef . current . focus ( ) ;
41- }
42- } ;
43-
44- // Listen for new task reset events
45- useEffect ( ( ) => {
46- const cleanup = NewTaskService . addResetListener ( resetTextarea ) ;
47- return cleanup ;
48- } , [ ] ) ;
49-
50- const handleSubmit = async ( ) => {
51- if ( input . trim ( ) ) {
52- try {
53- // Submit the input task using TaskService
54- const response = await TaskService . submitInputTask ( input . trim ( ) ) ;
55-
56- // Clear the input field
57- setInput ( "" ) ;
58- if ( textareaRef . current ) {
59- textareaRef . current . style . height = "auto" ;
60- }
61-
62- // Navigate to the plan page using the plan_id from the response
63- navigate ( `/plan/${ response . plan_id } ` ) ;
64-
65- } catch ( error ) {
66- console . error ( 'Failed to create task:' , error ) ;
67- // You can add error handling here if needed
68- }
69- }
70- } ;
71- const handleQuickTaskClick = ( task : QuickTask ) => {
72- // Copy task description to textarea
73- setInput ( task . description ) ;
74-
75- // Focus on textarea
76- if ( textareaRef . current ) {
77- textareaRef . current . focus ( ) ;
78- }
79-
80- // Call the onQuickTaskSelect with the task description
81- onQuickTaskSelect ( task . description ) ;
82- } ;
83-
84-
85- // Auto-resize textarea
86- useEffect ( ( ) => {
87- if ( textareaRef . current ) {
88- textareaRef . current . style . height = "auto" ;
89- textareaRef . current . style . height = `${ textareaRef . current . scrollHeight } px` ;
50+ textareaRef . current . style . height = "auto" ;
9051 }
91- } , [ input ] ) ;
9252
93- return (
94- < div className = "home-input-container" >
95- < div className = "home-input-content" >
96- < div className = "home-input-center-content" >
97- < div className = "home-input-title-wrapper" >
98- < Title2 > How can I help?</ Title2 >
53+ showToast ( "Task created!" , "success" ) ;
54+ navigate ( `/plan/${ response . plan_id } ` ) ;
55+ } catch ( error ) {
56+ console . error ( "Failed to create task:" , error ) ;
57+ showToast ( "Something went wrong" , "error" ) ;
58+ }
59+ }
60+ } ;
61+
62+ const handleQuickTaskClick = ( task : QuickTask ) => {
63+ setInput ( task . description ) ;
64+ if ( textareaRef . current ) {
65+ textareaRef . current . focus ( ) ;
66+ }
67+ onQuickTaskSelect ( task . description ) ;
68+ } ;
69+
70+ useEffect ( ( ) => {
71+ if ( textareaRef . current ) {
72+ textareaRef . current . style . height = "auto" ;
73+ textareaRef . current . style . height = `${ textareaRef . current . scrollHeight } px` ;
74+ }
75+ } , [ input ] ) ;
76+
77+ const handleClick = ( ) => {
78+ showToast ( "Creating a task plan..." , "error" , { dismissible : true } ) ;
79+ } ;
80+
81+ return (
82+ < div className = "home-input-container" >
83+ < div className = "home-input-content" >
84+ < div className = "home-input-center-content" >
85+ < div className = "home-input-title-wrapper" >
86+ < Title2 > How can I help?</ Title2 >
87+ </ div >
88+
89+ < ChatInput
90+ value = { input }
91+ placeholder = "Describe what you'd like to do or use / to reference files, people, and more"
92+ onChange = { setInput }
93+ >
94+ < Button
95+ appearance = "subtle"
96+ className = "home-input-send-button"
97+ onClick = { handleSubmit }
98+ disabled = { ! input . trim ( ) }
99+ icon = { < Send20Regular /> }
100+ />
101+ < Button
102+ appearance = "subtle"
103+ icon = { < FoodToast20Regular /> }
104+ onClick = { handleClick }
105+ > </ Button >
106+ </ ChatInput >
107+
108+ { /* Inline Toaster lives right under chat input */ }
109+ < InlineToaster />
110+
111+ < div className = "home-input-quick-tasks-section" >
112+ < div className = "home-input-quick-tasks-header" >
113+ < Body1Strong > Quick tasks</ Body1Strong >
114+ </ div >
115+ < div className = "home-input-quick-tasks" >
116+ { quickTasks . map ( ( task ) => (
117+ < Card
118+ key = { task . id }
119+ style = { {
120+ flex : "1 " ,
121+ display : "flex" ,
122+ flexDirection : "column" ,
123+ padding : "16px" ,
124+ backgroundColor : "var(--colorNeutralBackground3)" ,
125+ border : "1px solid var(--colorNeutralStroke2)" ,
126+ borderRadius : "8px" ,
127+ cursor : "pointer" ,
128+ boxShadow : "none" ,
129+ } }
130+ onMouseOver = { ( e ) =>
131+ ( e . currentTarget . style . backgroundColor =
132+ "var(--colorNeutralBackground4Hover)" )
133+ }
134+ onMouseOut = { ( e ) =>
135+ ( e . currentTarget . style . backgroundColor =
136+ "var(--colorNeutralBackground3)" )
137+ }
138+ onClick = { ( ) => handleQuickTaskClick ( task ) }
139+ >
140+ < div className = "home-input-quick-task-content" >
141+ < div className = "home-input-quick-task-icon" >
142+ { task . icon }
99143 </ div >
100-
101- < ChatInput
102- value = { input }
103- placeholder = "Describe what you'd like to do or use / to reference files, people, and more" onChange = { setInput } >
104- < Button
105- appearance = "subtle"
106- className = "home-input-send-button"
107- onClick = { handleSubmit }
108- disabled = { ! input . trim ( ) }
109- icon = { < Send20Regular /> }
110- />
111- </ ChatInput >
112-
113- < div className = "home-input-quick-tasks-section" >
114- < div className = "home-input-quick-tasks-header" >
115- < Body1Strong > Quick tasks</ Body1Strong >
116- </ div >
117- < div className = "home-input-quick-tasks" >
118- { quickTasks . map ( ( task ) => (
119- < Card
120- key = { task . id }
121- className = "home-input-quick-task-card"
122- onClick = { ( ) => handleQuickTaskClick ( task ) }
123- >
124- < div className = "home-input-quick-task-content" >
125- < div className = "home-input-quick-task-icon" >
126- { task . icon }
127- </ div >
128- < div className = "home-input-quick-task-text-content" >
129- < Body1Strong > { task . title } </ Body1Strong >
130- < Body1 className = "home-input-quick-task-description" >
131- { task . description }
132- </ Body1 >
133- </ div >
134- </ div >
135- </ Card >
136- ) ) }
137- </ div >
144+ < div className = "home-input-quick-task-text-content" >
145+ < Body1Strong > { task . title } </ Body1Strong >
146+ < Body1 className = "home-input-quick-task-description" >
147+ { task . description }
148+ </ Body1 >
138149 </ div >
139- </ div >
150+ </ div >
151+ </ Card >
152+ ) ) }
140153 </ div >
154+ </ div >
141155 </ div >
142- ) ;
143- }
156+ </ div >
157+ </ div >
158+ ) ;
159+ } ;
144160
145- export default HomeInput ;
161+ export default HomeInput ;
0 commit comments