think/packages/client/src/layouts/router-header/recent.tsx

131 lines
4.0 KiB
TypeScript
Raw Normal View History

2022-03-28 14:21:36 +00:00
import { IconChevronDown } from '@douyinfe/semi-icons';
2022-05-16 09:23:59 +00:00
import { Dropdown, Modal, Space, TabPane, Tabs, Typography } from '@douyinfe/semi-ui';
2022-03-28 14:21:36 +00:00
import { DataRender } from 'components/data-render';
import { DocumentStar } from 'components/document/star';
2022-05-16 09:23:59 +00:00
import { Empty } from 'components/empty';
2022-03-28 14:21:36 +00:00
import { IconDocumentFill } from 'components/icons/IconDocumentFill';
2022-05-16 09:23:59 +00:00
import { LocaleTime } from 'components/locale-time';
import { useRecentDocuments } from 'data/document';
2022-05-27 13:51:21 +00:00
import { useToggle } from 'hooks/use-toggle';
2022-05-16 09:23:59 +00:00
import Link from 'next/link';
2022-05-27 13:51:21 +00:00
import React, { useEffect } from 'react';
2022-05-16 09:23:59 +00:00
2022-03-28 14:21:36 +00:00
import styles from './index.module.scss';
2022-05-16 09:23:59 +00:00
import { Placeholder } from './placeholder';
2022-03-28 14:21:36 +00:00
const { Text } = Typography;
2022-05-27 13:51:21 +00:00
export const RecentDocs = ({ visible }) => {
const { data: recentDocs, loading, error, refresh } = useRecentDocuments();
useEffect(() => {
if (visible) {
refresh();
}
}, [visible, refresh]);
2022-03-28 14:21:36 +00:00
return (
2022-05-04 06:50:58 +00:00
<Tabs type="line" size="small">
<TabPane tab="文档" itemKey="docs">
<DataRender
loading={loading}
loadingContent={<Placeholder />}
error={error}
normalContent={() => {
return (
<div className={styles.itemsWrap} style={{ margin: '0 -16px' }}>
2022-05-27 13:51:21 +00:00
{recentDocs && recentDocs.length ? (
2022-05-04 06:50:58 +00:00
recentDocs.map((doc) => {
return (
<div className={styles.itemWrap} key={doc.id}>
<Link
href={{
pathname: '/wiki/[wikiId]/document/[documentId]',
query: {
wikiId: doc.wikiId,
documentId: doc.id,
},
}}
>
<a className={styles.item}>
<div className={styles.leftWrap}>
<IconDocumentFill style={{ marginRight: 12 }} />
<div>
<Text ellipsis={{ showTooltip: true }} style={{ width: 180 }}>
{doc.title}
</Text>
2022-03-28 14:21:36 +00:00
2022-05-04 06:50:58 +00:00
<Text size="small" type="tertiary">
2022-05-19 06:36:17 +00:00
{doc.createUser && doc.createUser.name} <LocaleTime date={doc.updatedAt} />
2022-05-04 06:50:58 +00:00
</Text>
</div>
</div>
<div className={styles.rightWrap}>
<DocumentStar documentId={doc.id} />
2022-03-28 14:21:36 +00:00
</div>
2022-05-04 06:50:58 +00:00
</a>
</Link>
</div>
);
})
) : (
<Empty message="最近访问的文档会出现在此处" />
)}
</div>
);
}}
/>
</TabPane>
</Tabs>
);
};
export const RecentModal = ({ visible, toggleVisible }) => {
return (
<Modal
centered
title="最近访问"
visible={visible}
footer={null}
onCancel={toggleVisible}
style={{ maxWidth: '96vw' }}
2022-03-28 14:21:36 +00:00
>
2022-05-05 02:32:47 +00:00
<div style={{ paddingBottom: 24 }}>
2022-05-27 13:51:21 +00:00
<RecentDocs visible={visible} />
2022-05-05 02:32:47 +00:00
</div>
2022-05-04 06:50:58 +00:00
</Modal>
);
};
export const RecentMobileTrigger = ({ toggleVisible }) => {
return <span onClick={toggleVisible}></span>;
};
export const Recent = () => {
2022-05-27 13:51:21 +00:00
const [visible, toggleVisible] = useToggle(false);
2022-05-04 06:50:58 +00:00
return (
<span>
<Dropdown
trigger="click"
spacing={16}
2022-05-27 13:51:21 +00:00
visible={visible}
onVisibleChange={toggleVisible}
2022-05-04 06:50:58 +00:00
content={
<div style={{ width: 300, padding: '16px 16px 0' }}>
2022-05-27 13:51:21 +00:00
<RecentDocs visible={visible} />
2022-05-04 06:50:58 +00:00
</div>
}
>
<span>
<Space>
<IconChevronDown />
</Space>
</span>
</Dropdown>
</span>
2022-03-28 14:21:36 +00:00
);
};