import React, { useMemo } from 'react'; import { CommonSidebarWrapper } from '@/components/CommonSidebarWrapper'; import { chatActions, InboxItem, isValidStr, model, t, useAppDispatch, useAsyncRequest, useInboxList, } from 'tailchat-shared'; import clsx from 'clsx'; import _orderBy from 'lodash/orderBy'; import { GroupName } from '@/components/GroupName'; import { ConverseName } from '@/components/ConverseName'; import { getMessageRender, pluginInboxItemMap } from '@/plugin/common'; import { useLocation } from 'react-router'; import { Link } from 'react-router-dom'; import { PillTabPane, PillTabs } from '@/components/PillTabs'; import { SectionHeader } from '@/components/SectionHeader'; import { openReconfirmModalP } from '@/components/Modal'; const buildLink = (itemId: string) => `/main/inbox/${itemId}`; /** * 收件箱侧边栏组件 */ export const InboxSidebar: React.FC = React.memo(() => { const inbox = useInboxList(); const list = useMemo(() => _orderBy(inbox, 'createdAt', 'desc'), [inbox]); const dispatch = useAppDispatch(); const renderInbox = (item: InboxItem) => { if (item.type === 'message') { const message: Partial = item.message ?? {}; let title: React.ReactNode = ''; if (isValidStr(message.groupId)) { title = ; } else if (isValidStr(message.converseId)) { title = ; } return ( ); } else if (pluginInboxItemMap[item.type]) { const info = pluginInboxItemMap[item.type]; const preview = info.getPreview(item); return ( ); } return null; }; const fullList = list; const unreadList = list.filter((item) => item.readed === false); const [, handleAllAck] = useAsyncRequest(async () => { unreadList.forEach((item) => { dispatch(chatActions.setInboxItemAck(item._id)); }); await model.inbox.setInboxAck(unreadList.map((item) => item._id)); }, [unreadList]); const [, handleClear] = useAsyncRequest(async () => { const res = await openReconfirmModalP({ title: t('确认清空收件箱么?'), }); if (res) { await model.inbox.clearInbox(); } }, [unreadList]); return ( {t('收件箱')}
{fullList.map((item) => renderInbox(item))} {unreadList.map((item) => renderInbox(item))}
); }); InboxSidebar.displayName = 'InboxSidebar'; const InboxSidebarItem: React.FC<{ title: React.ReactNode; desc: React.ReactNode; source: string; readed: boolean; to: string; }> = React.memo((props) => { const location = useLocation(); const isActive = location.pathname.startsWith(props.to); return (
{props.title ||  }
{props.desc}
{t('来自')}: {props.source}
); }); InboxSidebarItem.displayName = 'InboxSidebarItem';