Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 评论翻页
牛文政72b4df08a486
diff --git a/src/icp/reply.ts b/src/icp/reply.tsindex 285f3513..1fb5a94a 100644--- a/src/icp/reply.ts+++ b/src/icp/reply.ts@@ -31,11 +31,6 @@ export type CommentData = {subCommentList: CommentData[]; // 子数据};-export enum PageType {- paging = 'paging',- cursor = 'cursor',-}-/*** 获取作品列表*/@@ -43,9 +38,8 @@ export async function icpCreatorList(accountId: number, pcursor?: string) {const res: {list: WorkData[];pageInfo: {- pageType: PageType;- count?: number;- hasMore?: boolean;+ count: number;+ hasMore: boolean;pcursor?: string;};} = await window.ipcRenderer.invoke('ICP_CREATOR_LIST', accountId, pcursor);@@ -63,7 +57,7 @@ export async function icpGetCommentList(const res: {list: CommentData[];pageInfo: {- count?: number;+ count: number;hasMore: boolean;pcursor?: string;};diff --git a/src/views/reply/components/commentList.tsx b/src/views/reply/components/commentList.tsxindex 7ada6994..19e93fca 100644--- a/src/views/reply/components/commentList.tsx+++ b/src/views/reply/components/commentList.tsx@@ -6,10 +6,11 @@* @Description: 评论列表*/import { CommentData, icpGetCommentList, WorkData } from '@/icp/reply';-import { Avatar, Button, Card, Col, Modal, Row } from 'antd';+import { Avatar, Button, Card, Col, Modal, Row, Tooltip } from 'antd';import { forwardRef, useImperativeHandle, useRef, useState } from 'react';import Meta from 'antd/es/card/Meta';import ReplyComment, { ReplyCommentRef } from './replyComment';+import { MessageOutlined } from '@ant-design/icons';export interface CommentListRef {init: (accountId: number, workData: WorkData) => Promise<void>;@@ -21,11 +22,20 @@ const Com = forwardRef<CommentListRef>((props: any, ref) => {const [accountId, setAccountId] = useState<number>(0);const [workData, setWorkData] = useState<WorkData | null>(null);const Ref_ReplyComment = useRef<ReplyCommentRef>(null);+ const [pageInfo, setPageInfo] = useState<{+ count: number;+ hasMore: boolean;+ pcursor?: string;+ }>({+ count: 0,+ hasMore: false,+ });async function init(accountId: number, workData: WorkData) {setAccountId(accountId);setWorkData(workData);setIsModalOpen(true);+ await getCommentList(workData.dataId);}useImperativeHandle(ref, () => ({@@ -40,8 +50,11 @@ const Com = forwardRef<CommentListRef>((props: any, ref) => {* 获取评论列表*/async function getCommentList(dataId: string) {- const res = await icpGetCommentList(accountId, dataId);- setCommentList(res.list);+ const res = await icpGetCommentList(accountId, dataId, pageInfo.pcursor);+ if (!res) return;++ setPageInfo(res.pageInfo);+ setCommentList([...commentList, ...res.list]);}/**@@ -65,9 +78,6 @@ const Com = forwardRef<CommentListRef>((props: any, ref) => {style={{ width: 200 }}cover={<img alt="example" src={workData.coverUrl} />}>- <Button type="primary" onClick={() => getCommentList(workData.dataId)}>- 评论列表- </Button><Meta title={workData.title} /></Card>);@@ -84,26 +94,40 @@ const Com = forwardRef<CommentListRef>((props: any, ref) => {><Row><Col span={6}>{WorkDataDom()}</Col>-<Col span={18}>{commentList.map((item) => (- <Card key={item.commentId}>+ <Card key={item.commentId} className="mb-3"><p><Avatar src={item.headUrl} />{/* <p>{item.nikeName}</p> */}{item.content}- <Button type="primary" onClick={() => openReplyComment(item)}>- 回复- </Button>+ + <Tooltip title="回复">+ <MessageOutlined onClick={() => openReplyComment(item)} />+ </Tooltip></p>- {item.subCommentList.map((subItem) => (- <p key={subItem.commentId}>- <Avatar src={subItem.headUrl} />- {subItem.content}- </p>- ))}+ <div className="ml-6">+ {item.subCommentList.map((subItem) => (+ <p key={subItem.commentId}>+ <Avatar src={subItem.headUrl} />+ + {subItem.content}+ </p>+ ))}+ </div></Card>))}++ {commentList.length > 0 && (+ <p>+ <Button+ type="link"+ onClick={() => getCommentList(workData!.dataId)}+ >+ 加载更多+ </Button>+ </p>+ )}</Col></Row></Modal>diff --git a/src/views/reply/index.tsx b/src/views/reply/index.tsxindex bb33d6b5..9d55affd 100644--- a/src/views/reply/index.tsx+++ b/src/views/reply/index.tsx@@ -6,7 +6,7 @@* @Description: 评论页面 reply*/import { icpCreatorList, WorkData, icpCreateCommentList } from '@/icp/reply';-import { Col, message, Row, Tooltip } from 'antd';+import { Button, Col, message, Row, Tooltip } from 'antd';import { useCallback, useRef, useState } from 'react';import AccountSidebar from '../account/components/AccountSidebar/AccountSidebar';import ReplyWorks, { ReplyWorksRef } from './components/replyWorks';@@ -24,6 +24,14 @@ import styles from './reply.module.scss';export default function Page() {const [wordList, setWordList] = useState<WorkData[]>([]);const [activeAccountId, setActiveAccountId] = useState<number>(-1);+ const [pageInfo, setPageInfo] = useState<{+ count: number;+ hasMore: boolean;+ pcursor?: string;+ }>({+ count: 0,+ hasMore: false,+ });const Ref_ReplyWorks = useRef<ReplyWorksRef>(null);const Ref_AddAutoRun = useRef<AddAutoRunRef>(null);const Ref_CommentList = useRef<CommentListRef>(null);@@ -47,9 +55,9 @@ export default function Page() {async function getCreatorList(accountId: number) {if (accountId === -1) return;- setWordList([]);- const res = await icpCreatorList(accountId);- setWordList(res.list);+ const res = await icpCreatorList(accountId, pageInfo.pcursor);+ setPageInfo(res.pageInfo);+ setWordList([...wordList, ...res.list]);}/**@@ -153,6 +161,13 @@ export default function Page() {</Row></div>))}+ {wordList.length > 0 && (+ <p>+ <Button type="link" onClick={() => getCreatorList(activeAccountId)}>+ 加载更多+ </Button>+ </p>+ )}</div><ReplyWorks ref={Ref_ReplyWorks} />