From 3b0b5ff0320adcafedc83edc25732386bf02d8f1 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Mon, 6 Oct 2025 02:07:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BA=E7=BE=A4=E7=BB=84?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/ui/App.tsx | 6 +++ client/ui/AppMobile.tsx | 6 +++ client/ui/dialog/CreateGroupDialog.tsx | 54 ++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 client/ui/dialog/CreateGroupDialog.tsx diff --git a/client/ui/App.tsx b/client/ui/App.tsx index af66730..e97878e 100644 --- a/client/ui/App.tsx +++ b/client/ui/App.tsx @@ -21,6 +21,7 @@ import useAsyncEffect from "./useAsyncEffect.ts" import ChatInfoDialog from "./dialog/ChatInfoDialog.tsx" import Chat from "../api/client_data/Chat.ts" import AddContactDialog from './dialog/AddContactDialog.tsx' +import CreateGroupDialog from './dialog/CreateGroupDialog.tsx' import UserProfileDialog from "./dialog/UserProfileDialog.tsx" import DataCaches from "../api/DataCaches.ts" @@ -62,6 +63,7 @@ export default function App() { const [userInfo, setUserInfo] = React.useState(null as unknown as User) const addContactDialogRef = React.useRef(null) + const createGroupDialogRef = React.useRef(null) const chatInfoDialogRef = React.useRef(null) const [chatInfo, setChatInfo] = React.useState(null as unknown as Chat) @@ -152,6 +154,9 @@ export default function App() { + + @@ -179,6 +184,7 @@ export default function App() { } diff --git a/client/ui/AppMobile.tsx b/client/ui/AppMobile.tsx index 2a843ae..f380393 100644 --- a/client/ui/AppMobile.tsx +++ b/client/ui/AppMobile.tsx @@ -20,6 +20,7 @@ import useAsyncEffect from "./useAsyncEffect.ts" import ChatInfoDialog from "./dialog/ChatInfoDialog.tsx" import Chat from "../api/client_data/Chat.ts" import AddContactDialog from './dialog/AddContactDialog.tsx' +import CreateGroupDialog from './dialog/CreateGroupDialog.tsx' import UserProfileDialog from "./dialog/UserProfileDialog.tsx" import DataCaches from "../api/DataCaches.ts" @@ -58,6 +59,7 @@ export default function AppMobile() { }) const addContactDialogRef = React.useRef(null) + const createGroupDialogRef = React.useRef(null) const chatInfoDialogRef = React.useRef(null) const [chatInfo, setChatInfo] = React.useState(null as unknown as Chat) @@ -176,6 +178,9 @@ export default function AppMobile() { + + } diff --git a/client/ui/dialog/CreateGroupDialog.tsx b/client/ui/dialog/CreateGroupDialog.tsx new file mode 100644 index 0000000..ec28771 --- /dev/null +++ b/client/ui/dialog/CreateGroupDialog.tsx @@ -0,0 +1,54 @@ +import * as React from 'react' +import { Button, Dialog, TextField } from "mdui" +import useEventListener from "../useEventListener.ts" +import { checkApiSuccessOrSncakbar, snackbar } from "../snackbar.ts" +import Client from "../../api/Client.ts" + +import * as CryptoJS from 'crypto-js' +import data from "../../Data.ts" +import EventBus from "../../EventBus.ts" + +interface Refs { + createGroupDialogRef: React.MutableRefObject +} + +export default function CreateGroupDialog({ + createGroupDialogRef, +}: Refs) { + const inputGroupNameRef = React.useRef(null) + const inputGroupIdRef = React.useRef(null) + + async function createGroup() { + const re = await Client.invoke("Chat.createGroup", { + title: inputGroupNameRef.current!.value, + id: inputGroupIdRef.current!.value, + token: data.access_token, + }) + + if (checkApiSuccessOrSncakbar(re, "添加失敗")) return + snackbar({ + message: "创建成功!", + placement: "top", + }) + EventBus.emit('ContactsList.updateContacts') + + inputGroupNameRef.current!.value = '' + inputGroupIdRef.current!.value = '' + createGroupDialogRef.current!.open = false + } + + return ( + + { + if (event.key == 'Enter') + inputGroupIdRef.current!.click() + }}> + { + if (event.key == 'Enter') + createGroup() + }}> + createGroupDialogRef.current!.open = false}>取消 + createGroup()}>创建 + + ) +} \ No newline at end of file