import { useState, useRef, useEffect, useLayoutEffect } from "react"; import DeleteIcon from "../icons/delete.svg"; import styles from "./home.module.scss"; import { Message, SubmitKey, useChatStore, ChatSession, BOT_HELLO, } 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; }) { return (
{props.title}
{Locale.ChatItem.ChatItemCount(props.count)}
{props.time}
); } export function ChatList() { const [sessions, selectedIndex, selectSession, removeSession] = useChatStore( (state) => [ state.sessions, state.currentSessionIndex, state.selectSession, state.removeSession, ], ); return (
{sessions.map((item, i) => ( selectSession(i)} onDelete={() => (!isMobileScreen() || confirm(Locale.Home.DeleteChat)) && removeSession(i) } /> ))}
); }