fix: font loading and chat scrolling issues
- fix: Replace corrupted Merriweather fonts with valid WOFF2 files from @fontsource - fix: Use CSS @font-face instead of next/font/local for Merriweather (Next.js 16 compatibility) - fix: Add smart scroll detection to ChatWindow (respects manual scrolling) - feat: Update app title to "Brachnha Insight" - feat: Update app description Co-Authored-By: Claude (glm-4.7) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { ChatBubble } from './chat-bubble';
|
||||
import { TypingIndicator } from './typing-indicator';
|
||||
import { useChatStore } from '@/store/use-chat';
|
||||
@@ -9,11 +9,39 @@ import { BookOpen, Sparkles } from 'lucide-react';
|
||||
export function ChatWindow() {
|
||||
const { messages, isTyping } = useChatStore();
|
||||
const bottomRef = useRef<HTMLDivElement>(null);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const [isUserScrolling, setIsUserScrolling] = useState(false);
|
||||
|
||||
// Auto-scroll to bottom
|
||||
// Auto-scroll to bottom only when new messages arrive
|
||||
useEffect(() => {
|
||||
bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||
}, [messages, isTyping]);
|
||||
if (!isUserScrolling) {
|
||||
bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
}, [messages.length, isUserScrolling]);
|
||||
|
||||
// Detect when user is manually scrolling
|
||||
useEffect(() => {
|
||||
const container = containerRef.current;
|
||||
if (!container) return;
|
||||
|
||||
const handleScroll = () => {
|
||||
const { scrollTop, scrollHeight, clientHeight } = container;
|
||||
const isAtBottom = scrollHeight - scrollTop - clientHeight < 100;
|
||||
|
||||
// If user scrolls up from bottom, disable auto-scroll
|
||||
if (!isAtBottom && !isUserScrolling) {
|
||||
setIsUserScrolling(true);
|
||||
}
|
||||
|
||||
// If user scrolls back near bottom, re-enable auto-scroll
|
||||
if (isAtBottom && isUserScrolling) {
|
||||
setIsUserScrolling(false);
|
||||
}
|
||||
};
|
||||
|
||||
container.addEventListener('scroll', handleScroll);
|
||||
return () => container.removeEventListener('scroll', handleScroll);
|
||||
}, [isUserScrolling]);
|
||||
|
||||
if (!messages || messages.length === 0) {
|
||||
return (
|
||||
@@ -38,7 +66,7 @@ export function ChatWindow() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full flex-1 overflow-y-auto px-4 py-6 scroll-smooth">
|
||||
<div ref={containerRef} className="h-full flex-1 overflow-y-auto px-4 py-6 scroll-smooth">
|
||||
<div className="max-w-3xl mx-auto space-y-4">
|
||||
{messages.map((msg) => (
|
||||
<ChatBubble key={msg.id} role={msg.role} content={msg.content} />
|
||||
|
||||
Reference in New Issue
Block a user