diff --git a/frontend/src/conversation/Conversation.tsx b/frontend/src/conversation/Conversation.tsx index 10b5d186..2605629e 100644 --- a/frontend/src/conversation/Conversation.tsx +++ b/frontend/src/conversation/Conversation.tsx @@ -4,7 +4,7 @@ import { useDarkTheme } from '../hooks'; import Hero from '../Hero'; import { AppDispatch } from '../store'; import ConversationBubble from './ConversationBubble'; -import conversationSlice, { +import { addQuery, fetchAnswer, selectQueries, @@ -27,10 +27,14 @@ export default function Conversation() { const inputRef = useRef(null); const [isDarkTheme] = useDarkTheme(); const [hasScrolledToLast, setHasScrolledToLast] = useState(true); - const scrollRef = useRef(null); - const [eventInterrupt, setEventInterrupt] = useState(false); //interruptions caused during auto-scrolling + const conversationRef = useRef(null); const fetchStream = useRef(null); - const handleUserInterruption = () => setEventInterrupt(true); + const [eventInterrupt, setEventInterrupt] = useState(false); + useEffect(() => console.log(status, eventInterrupt)) + const handleUserInterruption = () => { + if (!eventInterrupt && status === "loading") + setEventInterrupt(true) + } useEffect(() => { !eventInterrupt && scrollIntoView(); }, [queries.length, queries[queries.length - 1]]); @@ -41,18 +45,15 @@ export default function Conversation() { element.focus(); } }, []); + useEffect(() => { - if (status === 'loading') { - scrollRef.current?.addEventListener('mousedown', handleUserInterruption); - scrollRef.current?.addEventListener('scroll', handleUserInterruption,{ passive: true }); - } return () => { if (status !== 'idle') { fetchStream.current && fetchStream.current.abort(); //abort previous stream } - scrollRef.current?.removeEventListener('scroll', handleUserInterruption); } }, [status]) + useEffect(() => { const observerCallback: IntersectionObserverCallback = (entries) => { entries.forEach((entry) => { @@ -78,12 +79,12 @@ export default function Conversation() { behavior: 'smooth', block: 'start', }); - }; + } const handleQuestion = (question: string) => { - setEventInterrupt(false); question = question.trim(); if (question === '') return; + setEventInterrupt(false) dispatch(addQuery({ prompt: question })); fetchStream.current = dispatch(fetchAnswer({ question })); }; @@ -133,7 +134,10 @@ export default function Conversation() { }; return ( -
+
{queries.length > 0 && !hasScrolledToLast && (