mirror of
https://github.com/PinkSheep27/SBU-Hackathon.git
synced 2026-10-10 23:50:26 -04:00
92 lines
3.7 KiB
TypeScript
92 lines
3.7 KiB
TypeScript
"use client";
|
|
import { useRef, useEffect } from "react";
|
|
import { ChatHistory } from "@/app/exportType/types";
|
|
import { User, Bot } from "lucide-react"
|
|
|
|
<<<<<<< HEAD
|
|
interface MessageWindowProps{
|
|
history :ChatHistory;
|
|
isLoading: boolean;
|
|
}
|
|
|
|
export default function MessageWindow({history, isLoading}:MessageWindowProps){
|
|
const messageEndRef = useRef<HTMLDivVElement>(null);
|
|
=======
|
|
interface MessageWindowProps {
|
|
history: ChatHistory
|
|
}
|
|
|
|
export default function MessageWindow({ history }: MessageWindowProps) {
|
|
const messageEndRef = useRef<HTMLDivElement>(null);
|
|
>>>>>>> ce9e6f34ed31b7bff736cc9ba9a1b8dcdec85f3a
|
|
|
|
useEffect(() => {
|
|
messageEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
}, [history]);
|
|
|
|
return (
|
|
<div className="flex-1 p-3 overflow-y-auto">
|
|
<div className="max-w-3xl mx-auto">
|
|
{history.map((msg, index) => {
|
|
const isUser = msg.role === "user"
|
|
|
|
return (
|
|
<div
|
|
key={index}
|
|
className={`flex ${isUser ? "justify-end" : "justify-start"}`}>
|
|
{!isUser && (
|
|
<div className="mr-2">
|
|
<div className="flex items-center justify-center w-8 h-8 rounded-full bg-gray">
|
|
<Bot size={15} className="text-gray-700">
|
|
</Bot>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
<div className={` px-4 py-2 shadow-sm rounded-lg
|
|
${isUser ? "bg-purple-600 text-white rounded-br-none" : "bg-white text-gray-800 rounded-bl-none"}
|
|
max-w-xs sm:max-w-md`}>
|
|
|
|
<div className="whitespace-pre-wrap break-words">{msg.parts.map((part, idx) => (
|
|
<span key={idx}>{part.text}</span>))}
|
|
</div>
|
|
</div>
|
|
{isUser && (
|
|
<div className="ml-2">
|
|
<div className="flex items-center justify-center w-8 h-8 rounded-full bg-purple-500">
|
|
<User size={16} className="text-white" />
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
<<<<<<< HEAD
|
|
);
|
|
})}
|
|
|
|
{isLoading && (
|
|
<div className="flex justify-start">
|
|
<div className="mr-2">
|
|
<div className="flex items-center justify-center w-8 h-8 rounded-full bg-gray">
|
|
<Bot size={15} className="text-gray-700" />
|
|
</div>
|
|
</div>
|
|
<div className="px-4 py-2 shadow-sm rounded-lg bg-white text-gray-800 rounded-bl-none max-w-xs sm:max-w-md">
|
|
<div className="whitespace-pre-wrap break-words">
|
|
<span>Loading...</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
{/* Invisible element to help scroll to bottom */}
|
|
<div ref={messageEndRef} />
|
|
=======
|
|
);
|
|
})}
|
|
|
|
{/* Invisible element to help scroll to bottom */}
|
|
<div ref={messageEndRef} />
|
|
</div>
|
|
>>>>>>> ce9e6f34ed31b7bff736cc9ba9a1b8dcdec85f3a
|
|
</div>
|
|
);
|
|
} |