diff --git a/packages/client/src/components/wiki/card/index.tsx b/packages/client/src/components/wiki/card/index.tsx index 5127fa93..e37a611b 100644 --- a/packages/client/src/components/wiki/card/index.tsx +++ b/packages/client/src/components/wiki/card/index.tsx @@ -9,11 +9,19 @@ import styles from './index.module.scss'; const { Text, Paragraph } = Typography; -export const WikiCard: React.FC<{ wiki: IWiki }> = ({ wiki }) => { +export const WikiCard: React.FC<{ wiki: IWiki; shareMode?: boolean }> = ({ + wiki, + shareMode = false, +}) => { return (
- - + +
; @@ -276,3 +277,24 @@ export const usePublicWikiTocs = (wikiId) => { return { data, loading, error, refresh: mutate }; }; + +/** + * 文档评论 + * @param documentId + * @returns + */ +export const useAllPublicWikis = () => { + const [page, setPage] = useState(1); + const { data, error, mutate } = useSWR<{ + data: Array; + total: number; + }>(`/wiki/public/wikis?page=${page}`, (url) => HttpClient.get(url)); + const loading = !data && !error; + + return { + data, + loading, + error, + setPage, + }; +}; diff --git a/packages/client/src/layouts/router-header/index.tsx b/packages/client/src/layouts/router-header/index.tsx index 00e6d712..bc46218b 100644 --- a/packages/client/src/layouts/router-header/index.tsx +++ b/packages/client/src/layouts/router-header/index.tsx @@ -78,6 +78,19 @@ export const RouterHeader: React.FC = () => { }); }, }, + { + itemKey: '/find', + text: ( + + 发现 + + ), + onClick: () => { + Router.push({ + pathname: `/find`, + }); + }, + }, ]} footer={ diff --git a/packages/client/src/pages/find/index.tsx b/packages/client/src/pages/find/index.tsx new file mode 100644 index 00000000..6854905f --- /dev/null +++ b/packages/client/src/pages/find/index.tsx @@ -0,0 +1,71 @@ +import type { NextPage } from 'next'; +import React from 'react'; +import { List, Pagination, Typography } from '@douyinfe/semi-ui'; +import { SingleColumnLayout } from 'layouts/single-column'; +import { useAllPublicWikis } from 'data/wiki'; +import { Empty } from 'components/empty'; +import { Seo } from 'components/seo'; +import { DataRender } from 'components/data-render'; +import { WikiCardPlaceholder, WikiCard } from 'components/wiki/card'; + +const grid = { + gutter: 16, + xs: 24, + sm: 12, + md: 12, + lg: 8, + xl: 8, +}; + +const { Title } = Typography; + +const Page: NextPage = () => { + const { data, loading, error, setPage } = useAllPublicWikis(); + + console.log(data); + + return ( + + +
+ + 发现 + + ( + ( + + + + )} + /> + )} + error={error} + normalContent={() => ( + <> + ( + + + + )} + emptyContent={} + /> +
+ +
+ + )} + /> +
+
+ ); +}; + +export default Page; diff --git a/packages/server/src/controllers/wiki.controller.ts b/packages/server/src/controllers/wiki.controller.ts index 0b725ccb..e1f1f8a8 100644 --- a/packages/server/src/controllers/wiki.controller.ts +++ b/packages/server/src/controllers/wiki.controller.ts @@ -174,4 +174,11 @@ export class WikiController { async getPublicWorkspaceDetail(@Param('id') wikiId) { return await this.wikiService.getPublicWikiDetail(wikiId); } + + @UseInterceptors(ClassSerializerInterceptor) + @Get('public/wikis') + @HttpCode(HttpStatus.OK) + async getAllPublicWikis(@Query() pagination: IPagination) { + return await this.wikiService.getAllPublicWikis(pagination); + } } diff --git a/packages/server/src/services/wiki.service.ts b/packages/server/src/services/wiki.service.ts index d3e197e8..6f2e3c27 100644 --- a/packages/server/src/services/wiki.service.ts +++ b/packages/server/src/services/wiki.service.ts @@ -604,4 +604,32 @@ export class WikiService { async getPublicWikiTocs(wikiId) { return await this.documentService.getPublicWikiTocs(wikiId); } + + /** + * 获取当前用户所有知识库 + * @param user + * @param pagination + * @returns + */ + async getAllPublicWikis(pagination: IPagination) { + const { page = 1, pageSize = 12 } = pagination; + const query = await this.wikiRepo + .createQueryBuilder('wiki') + .where('wiki.status=:status') + .setParameter('status', WikiStatus.public); + + query.skip((+page - 1) * +pageSize); + query.take(+pageSize); + + const [wikis, total] = await query.getManyAndCount(); + + const ret = await Promise.all( + wikis.map(async (wiki) => { + const createUser = await this.userService.findById(wiki.createUserId); + return { ...wiki, createUser }; + }) + ); + + return { data: ret, total }; + } }