mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
feat: local profile name autofill #1191
This commit is contained in:
@@ -4,7 +4,7 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { Box, Button, Typography } from "@mui/material";
|
import { Box, Button, Typography } from "@mui/material";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onChange: (value: string) => void;
|
onChange: (file: File, value: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FileInput = (props: Props) => {
|
export const FileInput = (props: Props) => {
|
||||||
@@ -28,7 +28,7 @@ export const FileInput = (props: Props) => {
|
|||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = (event) => {
|
reader.onload = (event) => {
|
||||||
resolve(null);
|
resolve(null);
|
||||||
onChange(event.target?.result as string);
|
onChange(file, event.target?.result as string);
|
||||||
};
|
};
|
||||||
reader.onerror = reject;
|
reader.onerror = reject;
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
|
|||||||
@@ -246,7 +246,15 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{isLocal && openType === "new" && (
|
{isLocal && openType === "new" && (
|
||||||
<FileInput onChange={(val) => (fileDataRef.current = val)} />
|
<FileInput
|
||||||
|
onChange={(file, val) => {
|
||||||
|
if (!formIns.getValues("name")) {
|
||||||
|
const name = file.name.substring(0, file.name.lastIndexOf("."));
|
||||||
|
formIns.setValue("name", name);
|
||||||
|
}
|
||||||
|
fileDataRef.current = val;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{isRemote && (
|
{isRemote && (
|
||||||
|
|||||||
Reference in New Issue
Block a user