Skip to content

Commit 3309df1

Browse files
feat(chat): refactor chat component for improved layout and image handling; update scroll behavior
1 parent 8bd41b7 commit 3309df1

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

components/custom/chat.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
21
"use client";
32

4-
import { useEffect, useState } from "react";
53
import { Attachment, Message } from "ai";
64
import { useChat } from "ai/react";
5+
import Image from "next/image";
6+
import { useEffect, useState } from "react";
77

88
import { Message as PreviewMessage } from "@/components/custom/message";
99
import { useScrollToBottom } from "@/components/custom/use-scroll-to-bottom";
@@ -40,7 +40,7 @@ export function Chat({
4040
if (messagesEndRef && messagesEndRef.current) {
4141
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
4242
}
43-
}, [messages.length, isLoading]);
43+
}, [messages.length, isLoading, messagesEndRef]);
4444

4545
return (
4646
<div className="flex flex-col items-center justify-center h-dvh w-dvw bg-background">
@@ -66,10 +66,10 @@ export function Chat({
6666
`}</style>
6767
{!hasUserMessages ? (
6868
// Initial state: centered input and logo
69-
<div className="flex flex-col items-center justify-center h-full w-full">
69+
<div className="flex flex-col items-center justify-center size-full">
7070
{/* Updated Rail logo */}
71-
<img src="/images/ir-logo.png" alt="Rail Logo" className="w-20 h-20 mb-6 rounded-full shadow object-cover" />
72-
<form className="flex flex-row gap-3 items-center w-full max-w-xl px-6">
71+
<Image src="/images/ir-logo.png" alt="Rail Logo" width={80} height={80} className="size-20 mb-6 rounded-full shadow object-cover" />
72+
<form className="flex flex-row gap-3 items-center size-full max-w-xl px-6">
7373
<MultimodalInput
7474
input={input}
7575
setInput={setInput}
@@ -85,7 +85,7 @@ export function Chat({
8585
</div>
8686
) : (
8787
// Chat state: messages and input at bottom
88-
<div className="flex flex-col justify-between items-center gap-6 h-full w-full">
88+
<div className="flex flex-col justify-between items-center gap-6 size-full">
8989
{/* Italian train route suggestions */}
9090
<div className="flex flex-row gap-6 mb-6">
9191
<button
@@ -112,7 +112,7 @@ export function Chat({
112112

113113
<div
114114
ref={messagesContainerRef}
115-
className="flex flex-col gap-4 h-full w-full max-w-2xl mx-auto overflow-y-scroll custom-scrollbar pb-32"
115+
className="flex flex-col gap-4 size-full max-w-2xl mx-auto overflow-y-scroll custom-scrollbar pb-32"
116116
>
117117
{messages.map((message) => (
118118
<PreviewMessage
@@ -124,14 +124,12 @@ export function Chat({
124124
toolInvocations={message.toolInvocations}
125125
/>
126126
))}
127-
128127
<div
129128
ref={messagesEndRef}
130129
className="shrink-0 min-w-[24px] min-h-[24px]"
131130
/>
132131
</div>
133-
134-
<form className="flex flex-row gap-3 fixed bottom-8 left-1/2 -translate-x-1/2 items-end w-full md:max-w-[700px] max-w-[calc(100dvw-32px)] px-6 md:px-0 z-10">
132+
<form className="flex flex-row gap-3 fixed bottom-8 left-1/2 -translate-x-1/2 items-end size-full md:max-w-[700px] max-w-[calc(100dvw-32px)] px-6 md:px-0 z-10">
135133
<MultimodalInput
136134
input={input}
137135
setInput={setInput}

0 commit comments

Comments
 (0)