Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#1446 from wsw2000/feat/switchWindow…
Browse files Browse the repository at this point in the history
…ScrollIntoView

feat: scrolling effect when switching chat windows
  • Loading branch information
Yidadaa committed May 13, 2023
2 parents 6bb0166 + 93c9974 commit 330504b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/components/chat-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Link, useNavigate } from "react-router-dom";
import { Path } from "../constant";
import { MaskAvatar } from "./mask";
import { Mask } from "../store/mask";
import { useRef, useEffect } from "react";

export function ChatItem(props: {
onClick?: () => void;
Expand All @@ -29,6 +30,14 @@ export function ChatItem(props: {
narrow?: boolean;
mask: Mask;
}) {
const draggableRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
if (props.selected && draggableRef.current) {
draggableRef.current?.scrollIntoView({
block: "center",
});
}
}, [props.selected]);
return (
<Draggable draggableId={`${props.id}`} index={props.index}>
{(provided) => (
Expand All @@ -37,7 +46,10 @@ export function ChatItem(props: {
props.selected && styles["chat-item-selected"]
}`}
onClick={props.onClick}
ref={provided.innerRef}
ref={(ele) => {
draggableRef.current = ele;
provided.innerRef(ele);
}}
{...provided.draggableProps}
{...provided.dragHandleProps}
title={`${props.title}\n${Locale.ChatItem.ChatItemCount(
Expand Down

0 comments on commit 330504b

Please sign in to comment.