11"use client"
22import React , { useState , useRef , useEffect } from "react"
3- import { IconLoader , IconSend } from "@tabler/icons-react"
3+ import { IconLoader , IconSend , IconUsersGroup } from "@tabler/icons-react"
44import { cn } from "@utils/cn"
55import { BorderTrail } from "@components/ui/border-trail"
66import { TextLoop } from "@components/ui/TextLoop"
77import toast from "react-hot-toast"
88
99const CreateTaskInput = ( { onTaskAdded, prompt, setPrompt } ) => {
10+ const [ isSwarmMode , setIsSwarmMode ] = useState ( false )
1011 const [ isSaving , setIsSaving ] = useState ( false )
1112 const textareaRef = useRef ( null )
1213
1314 useEffect ( ( ) => {
1415 const textarea = textareaRef . current
1516 if ( textarea ) {
1617 textarea . style . height = "auto"
17- textarea . style . height = `${ Math . min ( textarea . scrollHeight , 100 ) } px`
18+ textarea . style . height = `${ Math . min ( textarea . scrollHeight , 150 ) } px`
1819 }
1920 } , [ prompt ] )
2021
2122 const handleAddTask = async ( ) => {
23+ setIsSaving ( true )
24+ let payload = { }
25+
2226 if ( ! prompt . trim ( ) ) {
2327 toast . error ( "Please describe the task." )
28+ setIsSaving ( false )
2429 return
2530 }
26- setIsSaving ( true )
31+ payload = {
32+ prompt : prompt ,
33+ is_swarm : isSwarmMode
34+ }
35+
2736 try {
2837 const response = await fetch ( "/api/tasks/add" , {
2938 method : "POST" ,
3039 headers : { "Content-Type" : "application/json" } ,
31- body : JSON . stringify ( { prompt , assignee : "ai" } )
40+ body : JSON . stringify ( payload )
3241 } )
3342 const data = await response . json ( )
3443 if ( ! response . ok )
3544 throw new Error ( data . error || "Failed to add task" )
36- toast . success ( data . message || "Task added!" )
45+ toast . success (
46+ data . message ||
47+ ( isSwarmMode ? "Swarm task initiated!" : "Task added!" )
48+ )
3749 setPrompt ( "" )
3850 onTaskAdded ( )
3951 } catch ( error ) {
@@ -47,7 +59,8 @@ const CreateTaskInput = ({ onTaskAdded, prompt, setPrompt }) => {
4759 < div className = "p-4 flex-shrink-0 bg-transparent" >
4860 < div
4961 className = { cn (
50- "relative flex bg-brand-black rounded-full p-1 transition-all overflow-hidden min-h-[50px]"
62+ "relative flex bg-brand-black p-1 transition-all overflow-hidden" ,
63+ "rounded-full min-h-[50px]"
5164 ) }
5265 >
5366 < BorderTrail size = { 100 } className = "bg-brand-orange px-4" />
@@ -69,33 +82,62 @@ const CreateTaskInput = ({ onTaskAdded, prompt, setPrompt }) => {
6982 placeholder = " "
7083 className = "w-full rounded-l-full bg-transparent text-white placeholder-transparent border-1 border-brand-orange focus:ring-0 focus:ring-brand-black text-sm z-10 overflow-y-auto self-stretch py-2"
7184 />
85+
7286 { ! prompt && (
7387 < div className = "absolute top-1/2 left-4 right-12 -translate-y-1/2 text-neutral-500 pointer-events-none z-0 overflow-hidden" >
7488 < TextLoop className = "text-sm px-2 whitespace-normal md:whitespace-nowrap" >
75- < span > Create a task...</ span >
89+ < span >
90+ { isSwarmMode
91+ ? "Describe a swarm task..."
92+ : "Create a task..." }
93+ </ span >
7694 < span >
7795 Summarize my unread emails from today
7896 </ span >
7997 < span >
8098 Draft a follow-up to the project proposal
8199 </ span >
82100 < span >
83- Schedule a meeting with the design team
101+ { isSwarmMode
102+ ? "Research these topics: AI, ML, and Data Science"
103+ : "Schedule a meeting with the design team" }
84104 </ span >
85105 </ TextLoop >
86106 </ div >
87107 ) }
88- < button
89- onClick = { handleAddTask }
90- disabled = { isSaving || ! prompt . trim ( ) }
91- className = "p-3 bg-brand-orange rounded-r-full h-full text-brand-black disabled:opacity-50 hover:bg-opacity-80 transition-colors z-10 flex-shrink-0"
92- >
93- { isSaving ? (
94- < IconLoader size = { 18 } className = "animate-spin" />
95- ) : (
96- < IconSend size = { 18 } />
97- ) }
98- </ button >
108+ < div className = { cn ( "flex items-center gap-2 z-10" ) } >
109+ < button
110+ onClick = { ( ) => setIsSwarmMode ( ! isSwarmMode ) }
111+ className = { cn (
112+ "p-3 rounded-full h-full transition-colors" ,
113+ isSwarmMode
114+ ? "bg-blue-600 text-white"
115+ : "bg-neutral-800 text-neutral-300 hover:bg-neutral-700"
116+ ) }
117+ data-tooltip-id = "tasks-tooltip"
118+ data-tooltip-content = {
119+ isSwarmMode
120+ ? "Switch to Single Task Mode"
121+ : "Switch to Swarm Mode"
122+ }
123+ >
124+ < IconUsersGroup size = { 18 } />
125+ </ button >
126+ < button
127+ onClick = { handleAddTask }
128+ disabled = { isSaving || ! prompt . trim ( ) }
129+ className = "p-3 bg-brand-orange rounded-full h-full text-brand-black disabled:opacity-50 hover:bg-opacity-80 transition-colors flex-shrink-0"
130+ >
131+ { isSaving ? (
132+ < IconLoader
133+ size = { 18 }
134+ className = "animate-spin"
135+ />
136+ ) : (
137+ < IconSend size = { 18 } />
138+ ) }
139+ </ button >
140+ </ div >
99141 </ div >
100142 </ div >
101143 </ div >
0 commit comments