From eb060d2e43ad8901eaa07f8c8b4f1571e9b6efbf Mon Sep 17 00:00:00 2001 From: dongchengjie <37543964+dongchengjie@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:29:25 +0800 Subject: [PATCH] feat: local profile name autofill #1191 --- src/components/profile/file-input.tsx | 4 ++-- src/components/profile/profile-viewer.tsx | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/profile/file-input.tsx b/src/components/profile/file-input.tsx index 5357224a..2943d829 100644 --- a/src/components/profile/file-input.tsx +++ b/src/components/profile/file-input.tsx @@ -4,7 +4,7 @@ import { useTranslation } from "react-i18next"; import { Box, Button, Typography } from "@mui/material"; interface Props { - onChange: (value: string) => void; + onChange: (file: File, value: string) => void; } export const FileInput = (props: Props) => { @@ -28,7 +28,7 @@ export const FileInput = (props: Props) => { const reader = new FileReader(); reader.onload = (event) => { resolve(null); - onChange(event.target?.result as string); + onChange(file, event.target?.result as string); }; reader.onerror = reject; reader.readAsText(file); diff --git a/src/components/profile/profile-viewer.tsx b/src/components/profile/profile-viewer.tsx index ba70096a..14839dd8 100644 --- a/src/components/profile/profile-viewer.tsx +++ b/src/components/profile/profile-viewer.tsx @@ -246,7 +246,15 @@ export const ProfileViewer = forwardRef( )} {isLocal && openType === "new" && ( - (fileDataRef.current = val)} /> + { + if (!formIns.getValues("name")) { + const name = file.name.substring(0, file.name.lastIndexOf(".")); + formIns.setValue("name", name); + } + fileDataRef.current = val; + }} + /> )} {isRemote && (