UNPKG

general-assistant

Version:

General Assistant components

38 lines (37 loc) 2.13 kB
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime"; import { useEffect, useState, useContext } from 'react'; import { useStore } from 'zustand'; import StoreContext from '../../../_store/StoreContext'; import { getSnapshot } from '../../../_utils/tools'; export default function CitationContent() { const dataStore = useContext(StoreContext); const { citationInfo, setCitationInfo } = useStore(dataStore, (state) => ({ citationInfo: state.citationInfo, setCitationInfo: state.setCitationInfo, })); const [hasContent, setHasContent] = useState(!!citationInfo); const [content, setContent] = useState(citationInfo?.snapshoot); useEffect(() => { if (citationInfo === null || typeof citationInfo !== 'object') { setHasContent(false); return; } const { _id, snapshoot } = citationInfo; if (snapshoot) { setContent(_jsxs("div", { className: 'DS-GA-w-full DS-GA-h-fit DS-GA-text-white', children: [snapshoot, "2222"] })); } else { const _dom = document.querySelector(`[data-id="${_id}"] .allowCite`); if (_dom) { getSnapshot(_dom) .then((_src) => { setContent(_jsx("img", { className: 'DS-GA-max-h-16 DS-GA-object-cover', src: _src })); }) .catch((err) => setContent(_jsx("span", { children: err }))) .finally(() => setHasContent(true)); } } }, [citationInfo]); return (hasContent && _jsxs("div", { className: 'DS-GA-w-full DS-GA-flex DS-GA-justify-between DS-GA-items-center', children: [_jsx("div", { className: 'DS-GA-box-content DS-GA-max-h-16 DS-GA-grow DS-GA-overflow-auto DS-GA-p-2 DS-GA-rounded-lg DS-GA-bg-gray-200', children: content }), _jsx("i", { className: 'iconfont-assistant icon-del DS-GA-text-xxs DS-GA-h-4 DS-GA-w-4 DS-GA-ml-2 DS-GA-mr-[2px] DS-GA-p-1 DS-GA-text-text-reverse-9 DS-GA-bg-zinc-300 hover:DS-GA-bg-zinc-400 DS-GA-rounded-full DS-GA-cursor-pointer', onClick: () => setCitationInfo(null) })] })); }