Skip to content

Let's use AI to Earn!

feat: 评论

牛文政568b8bf0db0b
diff --git a/electron/main/plat/index.ts b/electron/main/plat/index.ts
index 38afb798..52443454 100644
--- a/electron/main/plat/index.ts
+++ b/electron/main/plat/index.ts
@@ -167,6 +167,38 @@ class PlatController {
const platform = this.platforms.get(account.type)!;
return await platform.getCommentList(account, dataId);
}
+
+ /**
+ * 创建评论
+ * @param account
+ * @param pageInfo
+ */
+ public async createComment(
+ account: AccountModel,
+ dataId: string,
+ content: string,
+ ) {
+ const platform = this.platforms.get(account.type)!;
+ return await platform.createComment(account, dataId, content);
+ }
+
+ /**
+ * 回复评论
+ * @param account
+ * @param pageInfo
+ */
+ public async replyComment(
+ account: AccountModel,
+ commentId: string,
+ content: string,
+ option: {
+ dataId?: string; // 作品ID
+ data: any; // 辅助数据,原数据
+ },
+ ) {
+ const platform = this.platforms.get(account.type)!;
+ return await platform.replyComment(account, commentId, content, option);
+ }
}
const platController = new PlatController();
diff --git a/electron/main/reply/controller.ts b/electron/main/reply/controller.ts
index a917b214..82d8ff67 100644
--- a/electron/main/reply/controller.ts
+++ b/electron/main/reply/controller.ts
@@ -60,4 +60,47 @@ export class ReplyController {
const res = await platController.getCommentList(account, dataId);
return res;
}
+
+ /**
+ * 创建评论
+ */
+ @Icp('ICP_CREATE_COMMENT')
+ async createComment(
+ event: Electron.IpcMainInvokeEvent,
+ accountId: number,
+ dataId: string,
+ content: string,
+ ): Promise<any> {
+ const account = await this.accountService.getAccountById(accountId);
+ if (!account) return null;
+
+ const res = await platController.createComment(account, dataId, content);
+ return res;
+ }
+
+ /**
+ * 回复评论
+ */
+ @Icp('ICP_REPLY_COMMENT')
+ async replyComment(
+ event: Electron.IpcMainInvokeEvent,
+ accountId: number,
+ commentId: string,
+ content: string,
+ option: {
+ dataId?: string; // 作品ID
+ data: any; // 辅助数据,原数据
+ },
+ ): Promise<any> {
+ const account = await this.accountService.getAccountById(accountId);
+ if (!account) return null;
+
+ const res = await platController.replyComment(
+ account,
+ commentId,
+ content,
+ option,
+ );
+ return res;
+ }
}
diff --git a/src/icp/reply.ts b/src/icp/reply.ts
index fc06d78d..ee2371b2 100644
--- a/src/icp/reply.ts
+++ b/src/icp/reply.ts
@@ -37,7 +37,7 @@ export async function icpCreatorList(
}
/**
- * 获取作品列表
+ * 获取评论列表
*/
export async function icpGetCommentList(accountId: number, dataId: string) {
const res: {
@@ -46,3 +46,42 @@ export async function icpGetCommentList(accountId: number, dataId: string) {
} = await window.ipcRenderer.invoke('ICP_COMMENT_LIST', accountId, dataId);
return res;
}
+
+/**
+ * 创建评论
+ */
+export async function icpCreateComment(
+ accountId: number,
+ dataId: string,
+ content: string,
+) {
+ const res: boolean = await window.ipcRenderer.invoke(
+ 'ICP_CREATE_COMMENT',
+ accountId,
+ dataId,
+ content,
+ );
+ return res;
+}
+
+/**
+ * 回复评论
+ */
+export async function icpReplyComment(
+ accountId: number,
+ commentId: string,
+ content: string,
+ option: {
+ dataId?: string; // 作品ID
+ data: any; // 辅助数据,原数据
+ },
+) {
+ const res: boolean = await window.ipcRenderer.invoke(
+ 'ICP_REPLY_COMMENT',
+ accountId,
+ commentId,
+ content,
+ option,
+ );
+ return res;
+}
diff --git a/src/views/reply/index.tsx b/src/views/reply/index.tsx
index f23b0937..07b574df 100644
--- a/src/views/reply/index.tsx
+++ b/src/views/reply/index.tsx
@@ -5,12 +5,19 @@
* @LastEditors: nevin
* @Description: 评论页面 reply
*/
-import { icpCreatorList, icpGetCommentList, WorkData } from '@/icp/reply';
+import {
+ icpCreateComment,
+ icpCreatorList,
+ icpGetCommentList,
+ icpReplyComment,
+ WorkData,
+} from '@/icp/reply';
import { Button } from 'antd';
import { useCallback, useState } from 'react';
import AccountSidebar from '../account/components/AccountSidebar/AccountSidebar';
export default function Page() {
const [wordList, setWordList] = useState<WorkData[]>([]);
+ const [commentList, setComment] = useState<WorkData[]>([]);
const [activeAccountId, setActiveAccountId] = useState<number>(-1);
async function getCreatorList() {
@@ -31,6 +38,33 @@ export default function Page() {
console.log('----- res', res);
}
+ /**
+ * 创建评论
+ */
+ async function createComment(dataId: string) {
+ const res = await icpCreateComment(activeAccountId, dataId, '真不错');
+ console.log('----- res', res);
+ }
+
+ /**
+ * 回复评论
+ */
+ async function replyComment(
+ commentId: string,
+ option: {
+ dataId?: string; // 作品ID
+ data: any; // 辅助数据,原数据
+ },
+ ) {
+ const res = await icpReplyComment(
+ activeAccountId,
+ commentId,
+ '真不错',
+ option,
+ );
+ console.log('----- res', res);
+ }
+
return (
<div>
<div>
@@ -38,13 +72,11 @@ export default function Page() {
activeAccountId={activeAccountId}
onAccountChange={useCallback((info) => {
setActiveAccountId(info.id);
+ getCreatorList();
}, [])}
/>
</div>
<div>
- <Button type="primary" onClick={getCreatorList}>
- 获取列表
- </Button>
<div>
{wordList.map((item) => (
<div key={item.dataId}>
@@ -55,6 +87,32 @@ export default function Page() {
>
获取评论列表
</Button>
+
+ <Button
+ type="primary"
+ onClick={() => {
+ createComment(item.dataId);
+ }}
+ >
+ 评论作品
+ </Button>
+ </div>
+ ))}
+ </div>
+ </div>
+ <div>
+ <div>
+ {commentList.map((item) => (
+ <div key={item.dataId}>
+ <p> {item.title}</p>
+ <p>
+ <Button
+ type="primary"
+ // onClick={() => replyComment(item.dataId)}
+ >
+ 回复该评论
+ </Button>
+ </p>
</div>
))}
</div>