import { type FC, useEffect, useState, useMemo, useRef } from 'react' import { useParams, useNavigate } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { Dropdown, Button } from 'antd' import { LoadingOutlined } from '@ant-design/icons'; import PageHeader from '../components/PageHeader' import StatementDetail from './StatementDetail' import ForgetDetail from './ForgetDetail' import ImplicitDetail from './ImplicitDetail' import ShortTermDetail from './ShortTermDetail' import PerceptualDetail from './PerceptualDetail' import EpisodicDetail from './EpisodicDetail' import ExplicitDetail from './ExplicitDetail' import WorkingDetail from './WorkingDetail' import { getEndUserProfile, } from '@/api/memory' import refreshIcon from '@/assets/images/refresh_hover.svg' import GraphDetail from './GraphDetail' const Detail: FC = () => { const { t } = useTranslation() const { id, type } = useParams() const navigate = useNavigate() const [name, setName] = useState('') const forgetDetailRef = useRef<{ handleRefresh: () => void }>(null) const statementDetailRef = useRef<{ handleRefresh: () => void }>(null) const implicitDetailRef = useRef<{ handleRefresh: () => void }>(null) useEffect(() => { if (!id) return getData() }, [id]) const getData = () => { if (!id) return getEndUserProfile(id).then((res) => { const response = res as { other_name: string; id: string; } setName(response.other_name || response.id) }) } const items = useMemo(() => { return ['PERCEPTUAL_MEMORY', 'WORKING_MEMORY', 'EMOTIONAL_MEMORY', 'SHORT_TERM_MEMORY', 'IMPLICIT_MEMORY', 'EPISODIC_MEMORY', 'EXPLICIT_MEMORY', 'FORGET_MEMORY'] .map(key => ({ key, label: t(`userMemory.${key}`) })) }, [t]) const onClick = ({ key }: { key: string }) => { navigate(`/user-memory/detail/${id}/${key}`, { replace: true }) } const [loading, setLoading] = useState(false) const handleRefresh = () => { setLoading(true) let response: any = null switch(type) { case 'FORGET_MEMORY': forgetDetailRef.current?.handleRefresh() break; case 'EMOTIONAL_MEMORY': response = statementDetailRef.current?.handleRefresh() break case 'IMPLICIT_MEMORY': response = implicitDetailRef.current?.handleRefresh() break } if (response instanceof Promise) { response.finally(() => { setLoading(false) }) } else { setLoading(false) } } if (type === 'GRAPH') { return } return (
- {type ? t(`userMemory.${type}`) : ''}
} extra={['FORGET_MEMORY', 'EMOTIONAL_MEMORY', 'IMPLICIT_MEMORY'].includes(type as string) && } />
{type === 'EMOTIONAL_MEMORY' && } {type === 'FORGET_MEMORY' && } {type === 'IMPLICIT_MEMORY' && } {type === 'SHORT_TERM_MEMORY' && } {type === 'PERCEPTUAL_MEMORY' && } {type === 'EPISODIC_MEMORY' && } {type === 'WORKING_MEMORY' && } {type === 'EXPLICIT_MEMORY' && }
) } export default Detail