-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Chat component to enhance message rendering and integrate lo…
…ading state
- Loading branch information
1 parent
c7605fa
commit 6b426ba
Showing
1 changed file
with
59 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,61 @@ | ||
export function Chat({} : {}) { | ||
import { Message } from "@/lib/messsages"; | ||
import { CapsuleSchema } from "@/lib/schema"; | ||
import { ExecutionResult } from "@/lib/types"; | ||
import { DeepPartial } from "ai"; | ||
import { LoaderIcon, Terminal } from "lucide-react"; | ||
|
||
export function Chat({ | ||
messages, | ||
isLoading, | ||
setCurrentPreview, | ||
}: { | ||
messages: Message[]; | ||
isLoading: boolean; | ||
setCurrentPreview: (preview: { | ||
capsule: DeepPartial<CapsuleSchema> | undefined; | ||
result: ExecutionResult | undefined; | ||
}) => void; | ||
}) { | ||
return ( | ||
<div> | ||
<h1>Chat Messages </h1> | ||
<div id="chat-container"> | ||
{messages.map((message: Message, index: number) => ( | ||
<div> | ||
{message.content.map((content, id) => { | ||
if (content.type === "text") { | ||
return content.text; | ||
} | ||
if (content.type === "image") { | ||
return ( | ||
<img key={id} src={content.image} alt="capsule" className="" /> | ||
); | ||
} | ||
})} | ||
{message.object && ( | ||
<div | ||
onClick={() => | ||
setCurrentPreview({ | ||
capsule: message.object, | ||
result: message.result, | ||
}) | ||
} | ||
> | ||
<div> | ||
<Terminal strokeWidth={2} className="" /> | ||
</div> | ||
<div> | ||
<span>{message.object.title}</span> | ||
<span>Click to see tiny code</span> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
))} | ||
{isLoading && ( | ||
<div> | ||
<LoaderIcon strokeWidth={2} className="animate-spin w-4 h-4" /> | ||
<span>Generating...</span> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
); | ||
} |