From 0f58129c748b232a619829d20d59ad6871b7300d Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Wed, 5 Oct 2022 00:03:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BA=E8=AF=9D=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/shared/hooks/useAsyncRequest.ts | 6 +- client/web/tailchat.d.ts | 1 + .../plugins/com.msgbyte.topic/.ministarrc.js | 2 +- .../services/topic.service.ts | 1 + .../plugins/com.msgbyte.topic/package.json | 4 +- .../src/components/modals/TopicCreate.tsx | 33 ++++++++ .../src/group/GroupTopicPanelRender.tsx | 37 ++++++--- .../plugins/com.msgbyte.topic/src/index.tsx | 3 +- .../com.msgbyte.topic/types/tailchat.d.ts | 75 +++++++++++++++++-- 9 files changed, 140 insertions(+), 22 deletions(-) create mode 100644 server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/src/components/modals/TopicCreate.tsx diff --git a/client/shared/hooks/useAsyncRequest.ts b/client/shared/hooks/useAsyncRequest.ts index cd427a21..06e05f0a 100644 --- a/client/shared/hooks/useAsyncRequest.ts +++ b/client/shared/hooks/useAsyncRequest.ts @@ -8,14 +8,14 @@ export function useAsyncRequest( fn: T, deps: DependencyList = [] ) { - const [{ loading }, call] = useAsyncFn(async (...args) => { + const [{ loading, value }, call] = useAsyncFn(async (...args: any[]) => { try { - await fn(...args); + return await fn(...args); } catch (err) { showErrorToasts(isDevelopment ? err : t('系统忙, 请稍后再试')); console.error(err); } }, deps); - return [{ loading }, call as T] as const; + return [{ loading, value }, call as T] as const; } diff --git a/client/web/tailchat.d.ts b/client/web/tailchat.d.ts index d793d59e..db546de0 100644 --- a/client/web/tailchat.d.ts +++ b/client/web/tailchat.d.ts @@ -310,6 +310,7 @@ declare module '@capital/component' { size?: 'small' | 'middle' | 'large'; shape?: 'circle' | 'square'; title?: string; + onClick?: React.MouseEventHandler; }>; export const PillTabs: any; diff --git a/server/plugins/com.msgbyte.topic/.ministarrc.js b/server/plugins/com.msgbyte.topic/.ministarrc.js index ab39d260..47fb5bdd 100644 --- a/server/plugins/com.msgbyte.topic/.ministarrc.js +++ b/server/plugins/com.msgbyte.topic/.ministarrc.js @@ -1,7 +1,7 @@ const path = require('path'); module.exports = { - externalDeps: ['react'], + externalDeps: ['react', 'styled-components'], pluginRoot: path.resolve(__dirname, './web'), outDir: path.resolve(__dirname, '../../public'), }; diff --git a/server/plugins/com.msgbyte.topic/services/topic.service.ts b/server/plugins/com.msgbyte.topic/services/topic.service.ts index fed32db8..d1000953 100644 --- a/server/plugins/com.msgbyte.topic/services/topic.service.ts +++ b/server/plugins/com.msgbyte.topic/services/topic.service.ts @@ -71,6 +71,7 @@ class GroupTopicService extends TcService { }) .limit(size) .skip((page - 1) * 20) + .sort({ _id: 'desc' }) .exec(); const json = await this.transformDocuments(ctx, {}, topic); diff --git a/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/package.json b/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/package.json index e48c780f..208ecc6a 100644 --- a/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/package.json +++ b/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/package.json @@ -8,6 +8,8 @@ "sync:declaration": "tailchat declaration github" }, "devDependencies": { - "react": "18.2.0" + "@types/styled-components": "^5.1.26", + "react": "18.2.0", + "styled-components": "^5.3.6" } } diff --git a/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/src/components/modals/TopicCreate.tsx b/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/src/components/modals/TopicCreate.tsx new file mode 100644 index 00000000..e4057413 --- /dev/null +++ b/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/src/components/modals/TopicCreate.tsx @@ -0,0 +1,33 @@ +import { useAsyncRequest } from '@capital/common'; +import { Button, ModalWrapper, TextArea } from '@capital/component'; +import React, { useState } from 'react'; +import styled from 'styled-components'; +import { Translate } from '../../translate'; + +const Footer = styled.div({ + textAlign: 'right', + paddingTop: 10, +}); + +export const TopicCreate: React.FC<{ + onCreate: (text: string) => Promise; +}> = React.memo((props) => { + const [text, setText] = useState(''); + + const [{ loading }, handleCreate] = useAsyncRequest(async () => { + await props.onCreate(text); + }, [text]); + + return ( + +