general-assistant
Version:
General Assistant components
56 lines (55 loc) • 4.1 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useTranslation } from 'react-i18next';
import { useContext } from 'react';
import { useStore } from 'zustand';
import StoreContext from '../_store/StoreContext';
import MyBtnRender from '../BtnRender';
import MyIconRender from '../IconRender';
import cn from 'classnames';
export default function History({ history }) {
const { t } = useTranslation();
const dataStore = useContext(StoreContext);
const { myHistoryList, topic, myTopicOpened, _getTemCreate, _myListContainer, MyHandlers, GlobalCtxs, } = useStore(dataStore, (state) => ({
myHistoryList: state.myHistoryList,
topic: state.topic,
myTopicOpened: state.myTopicOpened,
_getTemCreate: state._getTemCreate,
_myListContainer: state._myListContainer,
MyHandlers: state.MyHandlers,
GlobalCtxs: state.GlobalCtxs,
}));
const { onBeforeOpenChat } = MyHandlers;
const { hoverClassName, create, del, open = {}, expand } = history || {};
const { className: openClassName } = open;
const OperateRender = typeof expand === 'function' ? expand : undefined;
function _getTemDel(id) {
return Object.assign({ posi: 'left', title: t('delete') }, del, {
async onClick() {
let _flag = true;
if (typeof del?.onClick === 'function') {
_flag = await del.onClick({ data: id, ctx: GlobalCtxs });
}
if (_flag)
topic.del(id);
},
});
}
return (_jsxs(_Fragment, { children: [create && _jsx(MyBtnRender, { def: 'icon-add', Tem: _getTemCreate() }), _jsx("div", { className: 'DS-GA-grow DS-GA-h-24 DS-GA-mt-4 DS-GA-overflow-y-auto', ref: _myListContainer, children: Array.isArray(myHistoryList) &&
myHistoryList.map(item => {
const isActive = myTopicOpened === item.id;
const CustomItemRender = typeof item.Render === 'function' ? item.Render : undefined;
return (_jsxs("div", { className: cn('DS-GA-group DS-GA-py-2 DS-GA-px-3 DS-GA-mb-2 DS-GA-rounded-md DS-GA-cursor-pointer DS-GA-text-text-deep-9', hoverClassName ? hoverClassName : 'hover:DS-GA-bg-theme-shal-6 hover:DS-GA-text-text-reverse-9 hover:DS-GA-shadow-lg', isActive && (openClassName ? openClassName : 'DS-GA-bg-theme-shal-8 DS-GA-text-text-reverse-9 DS-GA-shadow-lg')), onClick: async () => {
if (item.id === myTopicOpened)
return;
let _flag = true;
if (typeof onBeforeOpenChat === 'function') {
_flag = await onBeforeOpenChat({
data: { currentId: myTopicOpened, afterId: item.id },
ctx: GlobalCtxs,
});
}
if (_flag)
topic.open(item.id);
}, children: [!CustomItemRender && _jsxs(_Fragment, { children: [_jsxs("div", { className: 'DS-GA-text-base DS-GA-mb-1 DS-GA-flex DS-GA-justify-between', children: [_jsx("p", { className: 'DS-GA-truncate DS-GA-max-w-full DS-GA-leading-8', children: item.title }), OperateRender && GlobalCtxs && _jsx(OperateRender, { data: item, ctx: GlobalCtxs }), !OperateRender && del && (_jsx("div", { className: 'DS-GA-w-8 DS-GA-h-8 DS-GA-hidden group-hover:DS-GA-flex DS-GA-items-center', onClick: event => event.stopPropagation(), children: _jsx(MyIconRender, { def: 'icon-del', Tem: _getTemDel(item.id) }) }))] }), _jsx("div", { className: cn('DS-GA-text-xs group-hover:DS-GA-text-text-reverse-9', isActive ? '' : 'DS-GA-text-text-deep-10'), children: _jsx("span", { children: item.time }) })] }), CustomItemRender && _jsx(CustomItemRender, { data: item, ctx: GlobalCtxs, ...item })] }, item.id));
}) })] }));
}