From fd4cdc286540125ed9440f09786a0eb3c3ed06bf Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 16 Oct 2022 01:42:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20topic=20=E7=82=B9=E5=87=BB=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E5=8A=A0=E8=BD=BD=E6=9B=B4=E5=A4=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/web/src/styles/antd/dark.less | 8 ++ .../src/group/GroupTopicPanelRender.tsx | 75 +++++++++++++++---- .../plugins/com.msgbyte.topic/src/store.ts | 12 ++- .../com.msgbyte.topic/src/translate.ts | 12 +++ 4 files changed, 91 insertions(+), 16 deletions(-) diff --git a/client/web/src/styles/antd/dark.less b/client/web/src/styles/antd/dark.less index 0322b167..07527740 100644 --- a/client/web/src/styles/antd/dark.less +++ b/client/web/src/styles/antd/dark.less @@ -49,6 +49,14 @@ &.ant-btn-link { border-color: transparent; + + &[disabled] { + &,&:hover, &:focus, &:active { + color: rgba(255, 255, 255, 0.25); + border-color: transparent; + background-color: transparent; + } + } } } diff --git a/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/src/group/GroupTopicPanelRender.tsx b/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/src/group/GroupTopicPanelRender.tsx index b27bd4d0..8584f528 100644 --- a/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/src/group/GroupTopicPanelRender.tsx +++ b/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/src/group/GroupTopicPanelRender.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect } from 'react'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; import { TopicCard } from '../components/TopicCard'; import { showSuccessToasts, @@ -26,6 +26,8 @@ const Root = styled(LoadingOnFirst)({ flexDirection: 'column', width: '100%', position: 'relative', + paddingTop: 10, + paddingBottom: 10, '.ant-empty': { paddingTop: 80, @@ -42,33 +44,62 @@ const Root = styled(LoadingOnFirst)({ }, }); +const PAGE_SIZE = 20; + const GroupTopicPanelRender: React.FC = React.memo(() => { const panelInfo = useGroupPanelContext(); const { panelId, groupId } = panelInfo; - const { topicMap, addTopicPanel, addTopicItem, updateTopicItem } = - useTopicStore(); + const { + topicMap, + addTopicPanel, + addTopicItem, + updateTopicItem, + resetTopicPanel, + } = useTopicStore(); const topicList = topicMap[panelId]; + const currentPageRef = useRef(1); + const [hasMore, setHasMore] = useState(true); - const [{ loading }, fetch] = useAsyncRequest(async () => { - if (!groupId || !panelId) { - return []; - } + const [{ loading }, fetch] = useAsyncRequest( + async (page = 1) => { + if (!groupId || !panelId) { + return []; + } - const { data } = await request.get('list', { - params: { + const { data: list } = await request.post('list', { groupId, panelId, - }, - }); - - addTopicPanel(panelId, data); - }, [groupId, panelId, addTopicPanel]); + page, + size: PAGE_SIZE, + }); + + if (Array.isArray(list)) { + addTopicPanel(panelId, list); + if (list.length !== PAGE_SIZE) { + // 没有更多了 + setHasMore(false); + } + } + }, + [groupId, panelId, addTopicPanel] + ); useEffect(() => { /** * 加载的时候获取列表 */ fetch(); + + return () => { + // 因为监听更新只在当前激活的面板中监听,还没添加到全局,因此为了保持面板状态需要清理面板状态 + // TODO: 增加群组级别的更新监听新增后可以移除 + resetTopicPanel(panelId); + }; + }, []); + + const handleLoadMore = useCallback(() => { + currentPageRef.current += 1; + fetch(currentPageRef.current); }, [fetch]); useGlobalSocketEvent( @@ -115,7 +146,21 @@ const GroupTopicPanelRender: React.FC = React.memo(() => { return ( {Array.isArray(topicList) && topicList.length > 0 ? ( - topicList.map((item, i) => ) + <> + {topicList.map((item, i) => ( + + ))} + + {hasMore ? ( + + ) : ( + + )} + ) : (