@@ -8,9 +8,10 @@ import { FileViewer } from "@/components/chat/file-viewer";
88import { SettingsView } from "@/components/chat/settings-view" ;
99import { ChatHeader } from "@/components/chat/chat-header" ;
1010import { WelcomeSection } from "@/components/chat/welcome-section" ;
11- import { MessageItem , type Message } from "@/components/chat/message-item" ;
11+ import { MessageItem } from "@/components/chat/message-item" ;
1212import { TypingIndicator } from "@/components/chat/typing-indicator" ;
1313import { ChatInput } from "@/components/chat/chat-input" ;
14+ import { type Message , isDraftSessionId , isGeneralSession } from "@/lib/types" ;
1415
1516export default function HomePage ( ) {
1617 const [ messages , setMessages ] = useState < Message [ ] > ( [ ] ) ;
@@ -26,10 +27,13 @@ export default function HomePage() {
2627 try {
2728 const data = await api . getTasks ( ) ;
2829 setTasks ( data ) ;
29- // Clear pending message if it now exists in tasks
30+ // Clear pending message only if task exists AND has output (response received)
3031 setPendingMessage ( ( prev ) => {
31- if ( prev && data . some ( ( t ) => t . prompt === prev . content ) ) {
32- return null ;
32+ if ( prev ) {
33+ const matchingTask = data . find ( ( t ) => t . prompt === prev . content ) ;
34+ if ( matchingTask && matchingTask . output ) {
35+ return null ;
36+ }
3337 }
3438 return prev ;
3539 } ) ;
@@ -46,17 +50,14 @@ export default function HomePage() {
4650
4751 // Update messages based on active session
4852 useEffect ( ( ) => {
49- // Check if this is a draft session
50- const isDraftSession = typeof activeSession === "string" && activeSession . startsWith ( "draft-" ) ;
51-
52- if ( isDraftSession ) {
53+ if ( isDraftSessionId ( activeSession ) ) {
5354 // Draft session - only show pending message if exists
5455 if ( pendingMessage ) {
5556 setMessages ( [ pendingMessage ] ) ;
5657 } else {
5758 setMessages ( [ ] ) ;
5859 }
59- } else if ( activeSession === "general" || ! activeSession ) {
60+ } else if ( isGeneralSession ( activeSession ) ) {
6061 // Show all messages for general session
6162 const taskMessages : Message [ ] = tasks . flatMap ( ( task ) => {
6263 const msgs : Message [ ] = [
@@ -118,9 +119,11 @@ export default function HomePage() {
118119 }
119120
120121 setMessages ( sessionMessages ) ;
121- } else {
122- setMessages ( [ ] ) ;
122+ } else if ( pendingMessage ) {
123+ // Task not found yet but we have a pending message - show it
124+ setMessages ( [ pendingMessage ] ) ;
123125 }
126+ // If no task and no pending message, keep previous messages (don't clear)
124127 }
125128 } , [ activeSession , tasks , pendingMessage ] ) ;
126129
@@ -142,8 +145,7 @@ export default function HomePage() {
142145 type : "text" ,
143146 } ;
144147
145- // Check if we're in a draft session
146- const isDraftSession = typeof activeSession === "string" && activeSession . startsWith ( "draft-" ) ;
148+ const wasDraftSession = isDraftSessionId ( activeSession ) ;
147149
148150 setPendingMessage ( userMessage ) ;
149151 setInput ( "" ) ;
@@ -154,8 +156,8 @@ export default function HomePage() {
154156 const newTask = await api . createTask ( input , workingDir , 1 ) ;
155157
156158 // If this was a draft session, remove it and switch to the new task
157- if ( isDraftSession ) {
158- removeDraftSession ( activeSession ) ;
159+ if ( wasDraftSession ) {
160+ removeDraftSession ( activeSession as `draft-${ string } ` ) ;
159161 // Switch to the new task's session
160162 if ( newTask ?. id ) {
161163 setActiveSession ( newTask . id ) ;
@@ -183,10 +185,9 @@ export default function HomePage() {
183185 const runningTask = tasks . find ( ( t ) => t . status === "running" ) ;
184186
185187 // Get current session name
186- const isDraftSession = typeof activeSession === "string" && activeSession . startsWith ( "draft-" ) ;
187- const currentSessionName = isDraftSession
188+ const currentSessionName = isDraftSessionId ( activeSession )
188189 ? "New Session"
189- : activeSession === "general" || ! activeSession
190+ : isGeneralSession ( activeSession )
190191 ? "General"
191192 : tasks . find ( ( t ) => t . id === activeSession ) ?. prompt . slice ( 0 , 30 ) || "Session" ;
192193
@@ -238,8 +239,18 @@ export default function HomePage() {
238239 ) ) }
239240 </ div >
240241
242+ { /* Running Indicator - show when task is running */ }
243+ { runningTask && (
244+ < div className = "px-6 py-2 mx-4" >
245+ < div className = "flex items-center gap-2 text-sm text-muted-foreground" >
246+ < div className = "w-2 h-2 bg-amber-500 rounded-full animate-pulse" />
247+ < span > Claude is working...</ span >
248+ </ div >
249+ </ div >
250+ ) }
251+
241252 { /* Typing Indicator */ }
242- { isTyping && < TypingIndicator /> }
253+ { isTyping && ! runningTask && < TypingIndicator /> }
243254 </ div >
244255 </ ScrollArea >
245256
0 commit comments