File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
commons/data-display/List
services/home/chat/TestSection Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 1- import { useEffect , useState } from "react" ;
1+ import { useEffect , useState , useRef } from "react" ;
22import { motion } from "framer-motion" ;
33import ServerItem from "./serveritem" ;
44
@@ -16,6 +16,12 @@ const chatContents = [
1616export default function TestChatList ( { onFinish } : { onFinish ?: ( ) => void } ) {
1717 const [ visibleCount , setVisibleCount ] = useState ( 0 ) ;
1818
19+ const bottomRef = useRef < HTMLDivElement | null > ( null ) ;
20+
21+ useEffect ( ( ) => {
22+ bottomRef . current ?. scrollIntoView ( { behavior : "smooth" } ) ;
23+ } , [ visibleCount ] ) ;
24+
1925 useEffect ( ( ) => {
2026 if ( visibleCount < chatContents . length ) {
2127 const timer = setTimeout ( ( ) => {
@@ -40,6 +46,7 @@ export default function TestChatList({ onFinish }: { onFinish?: () => void }) {
4046 < ServerItem contents = { contents } />
4147 </ motion . div >
4248 ) ) }
49+ < div ref = { bottomRef } />
4350 </ div >
4451 ) ;
4552}
Original file line number Diff line number Diff line change 1- import { useState , useEffect } from "react" ;
1+ import { useState , useEffect , useRef } from "react" ;
22import UmAvatar from "../../../../commons/data-display/Avatar" ;
33import TestChatList from "../../../../commons/data-display/List/testgroup" ;
44import TestToggle from "../TestToggle" ;
@@ -8,6 +8,11 @@ const TestSection = () => {
88 const [ isListFinished , setIsListFinished ] = useState ( false ) ;
99 const selectedTest = useChatStore ( ( state ) => state . suggestedTest || "phq-9" ) ;
1010 const setSelectedTest = useChatStore ( ( state ) => state . setSuggestedTest ) ;
11+ const bottomRef = useRef < HTMLDivElement | null > ( null ) ;
12+
13+ useEffect ( ( ) => {
14+ bottomRef . current ?. scrollIntoView ( { behavior : "smooth" } ) ;
15+ } , [ isListFinished ] ) ;
1116
1217 useEffect ( ( ) => {
1318 setSelectedTest ( "" ) ;
@@ -29,6 +34,7 @@ const TestSection = () => {
2934 < TestToggle selected = { selectedTest } onSelect = { setSelectedTest } />
3035 </ div >
3136 ) }
37+ < div ref = { bottomRef } />
3238 </ div >
3339 </ div >
3440 ) ;
You can’t perform that action at this time.
0 commit comments