@@ -13,9 +13,11 @@ import {
1313 DocumentEdit20Regular ,
1414} from "@fluentui/react-icons" ;
1515import React , { useRef , useEffect } from "react" ;
16+ import { useNavigate } from 'react-router-dom' ;
1617import "./../../styles/Chat.css" ; // Assuming you have a CSS file for additional styles
1718import "./../../styles/HomeInput.css" ;
18- import { HomeInputProps , quickTasks } from "../../models/homeInput" ;
19+ import { HomeInputProps , quickTasks , QuickTask } from "../../models/homeInput" ;
20+ import { TaskService } from "../../services/TaskService" ;
1921
2022
2123const HomeInput : React . FC < HomeInputProps > = ( {
@@ -24,16 +26,41 @@ const HomeInput: React.FC<HomeInputProps> = ({
2426} ) => {
2527 const [ inputValue , setInputValue ] = React . useState ( "" ) ;
2628 const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
29+ const navigate = useNavigate ( ) ;
2730
28- const handleSubmit = ( ) => {
31+ const handleSubmit = async ( ) => {
2932 if ( inputValue . trim ( ) ) {
30- onInputSubmit ( inputValue . trim ( ) ) ;
31- setInputValue ( "" ) ;
32- if ( textareaRef . current ) {
33- textareaRef . current . style . height = "auto" ;
33+ try {
34+ // Submit the input task using TaskService
35+ const response = await TaskService . submitInputTask ( inputValue . trim ( ) ) ;
36+
37+ // Clear the input field
38+ setInputValue ( "" ) ;
39+ if ( textareaRef . current ) {
40+ textareaRef . current . style . height = "auto" ;
41+ }
42+
43+ // Navigate to the plan page using the plan_id from the response
44+ navigate ( `/plan/${ response . plan_id } ` ) ;
45+
46+ } catch ( error ) {
47+ console . error ( 'Failed to create task:' , error ) ;
48+ // You can add error handling here if needed
3449 }
3550 }
3651 } ;
52+ const handleQuickTaskClick = ( task : QuickTask ) => {
53+ // Copy task description to textarea
54+ setInputValue ( task . description ) ;
55+
56+ // Focus on textarea
57+ if ( textareaRef . current ) {
58+ textareaRef . current . focus ( ) ;
59+ }
60+
61+ // Call the onQuickTaskSelect with the task description
62+ onQuickTaskSelect ( task . description ) ;
63+ } ;
3764
3865 const handleKeyPress = ( e : React . KeyboardEvent ) => {
3966 if ( e . key === "Enter" && ! e . shiftKey ) {
@@ -66,7 +93,6 @@ const HomeInput: React.FC<HomeInputProps> = ({
6693 className = "home-input-input-field"
6794 value = { inputValue }
6895 onChange = { ( e ) => setInputValue ( e . target . value ) }
69- onKeyPress = { handleKeyPress }
7096 placeholder = "Describe what you'd like to do or use / to reference files, people, and more"
7197 rows = { 1 }
7298 />
@@ -86,22 +112,21 @@ const HomeInput: React.FC<HomeInputProps> = ({
86112 < div className = "home-input-quick-tasks-header" >
87113 < Text className = "home-input-quick-tasks-title" > Quick tasks</ Text >
88114 </ div >
89- < div className = "home-input-quick-tasks" >
90- { quickTasks . map ( ( task ) => (
91- < Card
92- key = { task . id }
93- className = "home-input-quick-task-card"
94- onClick = { ( ) => onQuickTaskSelect ( task . id ) }
95- >
96- < div className = "home-input-card-content" >
97- < div className = "home-input-card-icon" > { task . icon } </ div >
98- < div className = "home-input-card-text-content" >
99- < Text className = "home-input-card-title" > { task . title } </ Text >
100- < Text className = "home-input-card-description" > { task . description } </ Text >
101- </ div >
115+ < div className = "home-input-quick-tasks" > { quickTasks . map ( ( task ) => (
116+ < Card
117+ key = { task . id }
118+ className = "home-input-quick-task-card"
119+ onClick = { ( ) => handleQuickTaskClick ( task ) }
120+ >
121+ < div className = "home-input-card-content" >
122+ < div className = "home-input-card-icon" > { task . icon } </ div >
123+ < div className = "home-input-card-text-content" >
124+ < Text className = "home-input-card-title" > { task . title } </ Text >
125+ < Text className = "home-input-card-description" > { task . description } </ Text >
102126 </ div >
103- </ Card >
104- ) ) }
127+ </ div >
128+ </ Card >
129+ ) ) }
105130 </ div >
106131 </ div >
107132 </ div >
0 commit comments