Skip to content

Commit 0d976aa

Browse files
committed
homepage working version
1 parent 1fa5e22 commit 0d976aa

File tree

3 files changed

+75
-23
lines changed

3 files changed

+75
-23
lines changed

src/frontend_react/src/components/content/HomeInput.tsx

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import {
1313
DocumentEdit20Regular,
1414
} from "@fluentui/react-icons";
1515
import React, { useRef, useEffect } from "react";
16+
import { useNavigate } from 'react-router-dom';
1617
import "./../../styles/Chat.css"; // Assuming you have a CSS file for additional styles
1718
import "./../../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

2123
const 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>

src/frontend_react/src/models/homeInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ export const quickTasks: QuickTask[] = [
3636

3737
export interface HomeInputProps {
3838
onInputSubmit: (input: string) => void;
39-
onQuickTaskSelect: (taskId: string) => void;
39+
onQuickTaskSelect: (taskDescription: string) => void;
4040
}

src/frontend_react/src/services/TaskService.ts renamed to src/frontend_react/src/services/TaskService.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { PlanWithSteps, PlanStatus } from '../models';
22
import { Task } from '../models/taskList';
33
import { apiService } from '../api/apiService';
4+
import { InputTask, InputTaskResponse } from '../models/inputTask';
45

56
/**
67
* TaskService - Service for handling task-related operations and transformations
@@ -77,6 +78,32 @@ export class TaskService {
7778
static filterTasksByStatus(tasks: Task[], status: 'inprogress' | 'completed'): Task[] {
7879
return tasks.filter(task => task.status === status);
7980
}
81+
82+
/**
83+
* Generate a session ID using the specified algorithm
84+
* @returns Generated session ID in format "sid_" + timestamp + "_" + random
85+
*/
86+
static generateSessionId(): string {
87+
const timestamp = new Date().getTime();
88+
const random = Math.floor(Math.random() * 10000);
89+
return `sid_${timestamp}_${random}`;
90+
}
91+
92+
/**
93+
* Submit an input task to create a new plan
94+
* @param description Task description
95+
* @returns Promise with the response containing session and plan IDs
96+
*/
97+
static async submitInputTask(description: string): Promise<InputTaskResponse> {
98+
const sessionId = this.generateSessionId();
99+
100+
const inputTask: InputTask = {
101+
session_id: sessionId,
102+
description: description
103+
};
104+
105+
return await apiService.submitInputTask(inputTask);
106+
}
80107
}
81108

82109
export default TaskService;

0 commit comments

Comments
 (0)