import { DragDropContext, Droppable, Draggable, OnDragEndResponder, } from "@hello-pangea/dnd"; import { useAppConfig, useChatStore } from "@/app/store"; import Locale from "@/app/locales"; import { useLocation, useNavigate } from "react-router-dom"; import { Path } from "@/app/constant"; import { Mask } from "@/app/store/mask"; import { useRef, useEffect } from "react"; import { showConfirm } from "@/app/components/ui-lib"; import AddIcon from "@/app/icons/addIcon.svg"; import NextChatTitle from "@/app/icons/nextchatTitle.svg"; import DeleteChatIcon from "@/app/icons/deleteChatIcon.svg"; import { getTime } from "@/app/utils"; import DeleteIcon from "@/app/icons/deleteIcon.svg"; import LogIcon from "@/app/icons/logIcon.svg"; import MenuLayout from "@/app/components/MenuLayout"; import Panel from "./ChatPanel"; import Popover from "@/app/components/Popover"; export function SessionItem(props: { onClick?: () => void; onDelete?: () => void; title: string; count: number; time: string; selected: boolean; id: string; index: number; narrow?: boolean; mask: Mask; }) { const draggableRef = useRef(null); useEffect(() => { if (props.selected && draggableRef.current) { draggableRef.current?.scrollIntoView({ block: "center", }); } }, [props.selected]); const { pathname: currentPath } = useLocation(); return ( {(provided) => (
{ draggableRef.current = ele; provided.innerRef(ele); }} {...provided.draggableProps} {...provided.dragHandleProps} title={`${props.title}\n${Locale.ChatItem.ChatItemCount( props.count, )}`} >
{props.title}
{getTime(props.time)}
{Locale.ChatItem.ChatItemCount(props.count)}
{ props.onDelete?.(); e.preventDefault(); e.stopPropagation(); }} >
{Locale.Chat.Actions.Delete}
} className="" >
)}
); } export default MenuLayout(function SessionList(props) { const { setShowPanel } = props; const [sessions, selectedIndex, selectSession, moveSession] = useChatStore( (state) => [ state.sessions, state.currentSessionIndex, state.selectSession, state.moveSession, ], ); const navigate = useNavigate(); const config = useAppConfig(); const { isMobileScreen } = config; const chatStore = useChatStore(); const { pathname: currentPath } = useLocation(); useEffect(() => { setShowPanel?.(currentPath === Path.Chat); }, [currentPath]); 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 (
{ if (config.dontShowMaskSplashScreen) { chatStore.newSession(); navigate(Path.Chat); } else { navigate(Path.NewChat); } }} >
Build your own AI assistant.
{ if (e.target === e.currentTarget) { navigate(Path.Home); } }} > {(provided) => (
{sessions.map((item, i) => ( { navigate(Path.Chat); selectSession(i); }} onDelete={async () => { if ( !isMobileScreen || (await showConfirm(Locale.Home.DeleteChat)) ) { chatStore.deleteSession(i); } }} mask={item.mask} /> ))} {provided.placeholder}
)}
); }, Panel);