import DeleteIcon from "../icons/delete.svg"; import BotIcon from "../icons/bot.svg"; import styles from "./home.module.scss"; import { DragDropContext, Droppable, Draggable, OnDragEndResponder, } from "@hello-pangea/dnd"; import { useChatStore } from "../store"; import Locale from "../locales"; import { Link, useNavigate } from "react-router-dom"; import { Path } from "../constant"; import { MaskAvatar } from "./mask"; import { Mask } from "../store/mask"; export function ChatItem(props: { onClick?: () => void; onDelete?: () => void; title: string; count: number; time: string; selected: boolean; id: number; index: number; narrow?: boolean; mask: Mask; }) { return ( {(provided) => ( {props.narrow ? ( {props.count} ) : ( <> {props.title} {Locale.ChatItem.ChatItemCount(props.count)} {new Date(props.time).toLocaleString()} > )} )} ); } 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 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 ( {(provided) => ( {sessions.map((item, i) => ( { navigate(Path.Chat); selectSession(i); }} onDelete={() => { if (!props.narrow || confirm(Locale.Home.DeleteChat)) { chatStore.deleteSession(i); } }} narrow={props.narrow} mask={item.mask} /> ))} {provided.placeholder} )} ); }