import DeleteIcon from "../icons/delete.svg"; import styles from "./home.module.scss"; import { DragDropContext, Droppable, Draggable, OnDragEndResponder, DraggableProvided, } from "@hello-pangea/dnd"; import { useChatStore } from "../store"; import Locale from "../locales"; import { useLocation, useNavigate } from "react-router-dom"; import { Path } from "../constant"; import { MaskAvatar } from "./mask"; import { Mask } from "../store/mask"; import { useRef, useEffect } from "react"; import { showConfirm } from "./ui-lib"; import { useMobileScreen } from "../utils"; // motion import QueueAnim from "rc-queue-anim"; function ChatItem(props: { onClick?: () => void; onDelete?: () => void; title: string; count: number; time: string; selected: boolean; id: string; index: number; narrow?: boolean; mask: Mask; provided: DraggableProvided; isMobileScreen: boolean; }) { const draggableRef = useRef(null); useEffect(() => { if (props.selected && draggableRef.current) { draggableRef.current?.scrollIntoView({ block: "center", }); } }, [props.selected]); const { pathname: currentPath } = useLocation(); return (
{ draggableRef.current = ele; props.provided.innerRef(ele); }} {...(props.isMobileScreen ? {} : props.provided.draggableProps)} {...(props.isMobileScreen ? {} : props.provided.dragHandleProps)} title={`${props.title}\n${Locale.ChatItem.ChatItemCount(props.count)}`} > {props.narrow ? (
{props.count}
) : ( <>
{props.title}
{Locale.ChatItem.ChatItemCount(props.count)}
{props.time}
)}
{ props.onDelete?.(); e.preventDefault(); e.stopPropagation(); }} >
); } export function ChatList(props: { narrow?: boolean }) { const [sessions, selectedIndex, selectSession, moveSession] = useChatStore( (state) => [ state.sessions, state.currentSessionIndex, state.selectSession, state.moveSession, ], ); const chatStore = useChatStore(); const navigate = useNavigate(); const isMobileScreen = useMobileScreen(); const onDragEnd: OnDragEndResponder = (result) => { const { destination, source } = result; if (!destination) { return; } if ( destination.droppableId === source.droppableId && destination.index === source.index ) { return; } moveSession(source.index, destination.index); }; return ( ( { navigate(Path.Chat); selectSession(rubic.source.index); }} onDelete={async () => { if ( (!props.narrow && !isMobileScreen) || (await showConfirm(Locale.Home.DeleteChat)) ) { chatStore.deleteSession(rubic.source.index); } }} narrow={props.narrow} mask={sessions[rubic.source.index].mask} provided={provided} isMobileScreen={isMobileScreen} /> )} > {(provided, snapshot) => (
{ if (type === "enter") target.style.height = "auto"; }} // interval={150} > {sessions.map((item, i) => (
{(provided, snapshot) => ( { navigate(Path.Chat); selectSession(i); }} onDelete={async () => { if ( (!props.narrow && !isMobileScreen) || (await showConfirm(Locale.Home.DeleteChat)) ) { chatStore.deleteSession(i); } }} narrow={props.narrow} mask={item.mask} provided={provided} isMobileScreen={isMobileScreen} /> )}
))}
{provided.placeholder}
)}
); }