Co-authored-by: Sharang Parnerkar <parnerkarsharang@gmail.com> Reviewed-on: #10
39 lines
1.2 KiB
Rust
39 lines
1.2 KiB
Rust
use crate::components::{ChatBubble, StreamingBubble};
|
|
use crate::models::ChatMessage;
|
|
use dioxus::prelude::*;
|
|
|
|
/// Scrollable message list that renders all messages in a chat session.
|
|
///
|
|
/// Auto-scrolls to the bottom when new messages arrive or during streaming.
|
|
/// Shows a streaming bubble with a blinking cursor when `is_streaming` is true.
|
|
///
|
|
/// # Arguments
|
|
///
|
|
/// * `messages` - All loaded messages for the current session
|
|
/// * `streaming_content` - Accumulated content from the SSE stream
|
|
/// * `is_streaming` - Whether a response is currently streaming
|
|
#[component]
|
|
pub fn ChatMessageList(
|
|
messages: Vec<ChatMessage>,
|
|
streaming_content: String,
|
|
is_streaming: bool,
|
|
) -> Element {
|
|
rsx! {
|
|
div {
|
|
class: "chat-message-list",
|
|
id: "chat-message-list",
|
|
if messages.is_empty() && !is_streaming {
|
|
div { class: "chat-empty",
|
|
p { "Send a message to start the conversation." }
|
|
}
|
|
}
|
|
for msg in &messages {
|
|
ChatBubble { key: "{msg.id}", message: msg.clone() }
|
|
}
|
|
if is_streaming {
|
|
StreamingBubble { content: streaming_content }
|
|
}
|
|
}
|
|
}
|
|
}
|