Skip to content

Commit

Permalink
Refactor Chat component to enhance message rendering and integrate lo…
Browse files Browse the repository at this point in the history
…ading state
  • Loading branch information
eraykeskinmac committed Dec 7, 2024
1 parent c7605fa commit 6b426ba
Showing 1 changed file with 59 additions and 5 deletions.
64 changes: 59 additions & 5 deletions components/chat.tsx
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>
)
}
);
}

0 comments on commit 6b426ba

Please sign in to comment.