import DeleteIcon from "../icons/delete.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 { isMobileScreen } from "../utils"; export function ChatItem(props: { onClick?: () => void; onDelete?: () => void; title: string; count: number; time: string; selected: boolean; id: number; index: number; }) { return ( {(provided) => (
{props.title}
{Locale.ChatItem.ChatItemCount(props.count)}
{props.time}
)}
); } export function ChatList() { const [sessions, selectedIndex, selectSession, removeSession, moveSession] = useChatStore((state) => [ state.sessions, state.currentSessionIndex, state.selectSession, state.removeSession, state.moveSession, ]); 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) => ( selectSession(i)} onDelete={() => (!isMobileScreen() || confirm(Locale.Home.DeleteChat)) && removeSession(i) } /> ))} {provided.placeholder}
)}
); }