From 505e629f3057d69d6548807a7b145fffe75ed037 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sun, 14 Dec 2025 00:13:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E4=B8=8D=E7=9F=A5=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/ui/ImageViewer.tsx | 15 ++-- client/ui/Main.tsx | 12 ++- client/ui/routers/EditMyProfileDialog.tsx | 98 ++++++++++++++++++++++ client/ui/routers/UserOrChatInfoDialog.tsx | 6 +- 4 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 client/ui/routers/EditMyProfileDialog.tsx diff --git a/client/ui/ImageViewer.tsx b/client/ui/ImageViewer.tsx index ee06537..86e51a8 100644 --- a/client/ui/ImageViewer.tsx +++ b/client/ui/ImageViewer.tsx @@ -2,18 +2,23 @@ import { Dialog } from 'mdui' import 'pinch-zoom-element' import React from "react" -export default function ImageViewer() { +export default function ImageViewer({ ...props }: React.ImgHTMLAttributes) { const dialogRef = React.useRef() - + return - + window.open(props.src, '_blank')}> dialogRef.current!.open = false}> { // @ts-ignore 注册了这个元素 - + + + {/* @ts-ignore 注册了这个元素 */} + } } diff --git a/client/ui/Main.tsx b/client/ui/Main.tsx index d7f2e2c..33a4cde 100644 --- a/client/ui/Main.tsx +++ b/client/ui/Main.tsx @@ -24,6 +24,7 @@ import ChatFragmentDialog from "./routers/ChatFragmentDialog.tsx" import EffectOnly from "./EffectOnly.tsx" import MainSharedReducer from "./MainSharedReducer.ts" import gotoUserInfo from "./routers/gotoUserInfo.ts" +import EditMyProfileDialog from "./routers/EditMyProfileDialog.tsx" function Root() { const [myProfileCache, setMyProfileCache] = React.useState() @@ -129,8 +130,6 @@ function Root() { }}> 添加收藏对话 创建新的群组 - 我是测试 - 我是测试2
() + useAsyncEffect(async () => setMySelf(await ClientCache.getMySelf() as UserMySelf)) + + const chooseAvatarFileRef = React.useRef(null) + + const editNickNameRef = React.useRef(null) + const editUserNameRef = React.useRef(null) + + useEventListener(chooseAvatarFileRef, 'change', async (_) => { + const file = chooseAvatarFileRef.current!.files?.[0] as File + if (file == null) return + + try { + const hash = await getClient().uploadFile({ + fileName: 'UserAvatar', + fileData: file, + }) + await mySelf?.setAvatarFileHashOrThrow(hash) + } catch (e) { + if (e instanceof CallbackError) + showSnackbar({ + message: '上传头像失败: ' + e.message + }) + } + + showSnackbar({ + message: "修改成功, 刷新页面以更新", + }) + }) + + return ( + +
+ +
+ +
+ + +
+ + + { + const input = e.target as HTMLInputElement + input.select() + input.setSelectionRange(0, 1145141919810) + }}> + + + nav(-1)}>取消 + { + try { + await mySelf?.updateProfileOrThrow({ + nickname: editNickNameRef.current?.value, + username: editUserNameRef.current?.value, + }) + } catch (e) { + if (e instanceof CallbackError) + showSnackbar({ + message: '更新资料失败: ' + e.message + }) + } + showSnackbar({ + message: "修改成功, 刷新页面以更新", + }) + }}>更新 +
+ ) +} \ No newline at end of file diff --git a/client/ui/routers/UserOrChatInfoDialog.tsx b/client/ui/routers/UserOrChatInfoDialog.tsx index b0882c1..dc6dfd7 100644 --- a/client/ui/routers/UserOrChatInfoDialog.tsx +++ b/client/ui/routers/UserOrChatInfoDialog.tsx @@ -1,6 +1,6 @@ import { dialog } from "mdui" import useRouterDialogRef from "./useRouterDialogRef" -import { useLoaderData } from "react-router" +import { useLoaderData, useNavigate } from "react-router" import { CallbackError } from "lingchair-client-protocol" import showSnackbar from "../../utils/showSnackbar" import Avatar from "../Avatar" @@ -16,6 +16,8 @@ export default function UserOrChatInfoDialog() { state: context.state, })) + const nav = useNavigate() + const dialogRef = useRouterDialogRef() const { chat, id, mySelf } = useLoaderData() @@ -56,7 +58,7 @@ export default function UserOrChatInfoDialog() { }}> { - isMySelf && + isMySelf && nav('/settings/edit_profile')}> 编辑资料 }