refactor(dashboard): simplify chat rendering and add scroll behavior
Removes unnecessary complexity from ChatMessages while adding proper scroll management to SessionCard: ChatMessages.js: - Remove scroll position tracking refs and effects (wasAtBottomRef, prevMessagesLenRef, containerRef) - Remove spinner display logic (moved to parent components) - Simplify to pure message filtering and rendering - Add display limit (last 20 messages) with offset tracking for keys SessionCard.js: - Add chatPaneRef for scroll container - Add useEffect to scroll to bottom when conversation updates - Provides natural "follow" behavior for new messages The refactor moves scroll responsibility to the component that owns the scroll container, reducing prop drilling and effect complexity. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { html, useEffect } from '../lib/preact.js';
|
||||
import { html, useEffect, useRef } from '../lib/preact.js';
|
||||
import { getStatusMeta } from '../utils/status.js';
|
||||
import { formatDuration, getContextUsageSummary } from '../utils/formatting.js';
|
||||
import { ChatMessages } from './ChatMessages.js';
|
||||
@@ -19,6 +19,14 @@ export function SessionCard({ session, onClick, conversation, onFetchConversatio
|
||||
}
|
||||
}, [session.session_id, session.project_dir, agent, conversation, onFetchConversation]);
|
||||
|
||||
const chatPaneRef = useRef(null);
|
||||
|
||||
// Scroll chat pane to bottom when conversation loads or updates
|
||||
useEffect(() => {
|
||||
const el = chatPaneRef.current;
|
||||
if (el) el.scrollTop = el.scrollHeight;
|
||||
}, [conversation]);
|
||||
|
||||
const handleDismissClick = (e) => {
|
||||
e.stopPropagation();
|
||||
onDismiss(session.session_id);
|
||||
@@ -26,7 +34,7 @@ export function SessionCard({ session, onClick, conversation, onFetchConversatio
|
||||
|
||||
return html`
|
||||
<div
|
||||
class="glass-panel flex h-[850px] max-h-[850px] w-[600px] cursor-pointer flex-col overflow-hidden rounded-xl border border-selection/70 transition-all duration-200 hover:border-starting/35 hover:shadow-panel"
|
||||
class="glass-panel flex h-[850px] max-h-[850px] w-[600px] cursor-pointer flex-col overflow-hidden rounded-xl border border-selection/70 transition-[border-color,box-shadow] duration-200 hover:border-starting/35 hover:shadow-panel"
|
||||
style=${{ borderLeftWidth: '3px', borderLeftColor: statusMeta.borderColor }}
|
||||
onClick=${() => onClick(session)}
|
||||
>
|
||||
@@ -77,7 +85,7 @@ export function SessionCard({ session, onClick, conversation, onFetchConversatio
|
||||
</div>
|
||||
|
||||
<!-- Card Content Area (Chat) -->
|
||||
<div class="flex-1 min-h-0 overflow-y-auto bg-surface px-4 py-4">
|
||||
<div ref=${chatPaneRef} class="flex-1 min-h-0 overflow-y-auto bg-surface px-4 py-4">
|
||||
<${ChatMessages} messages=${conversation || []} status=${session.status} />
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user