Remove mui-file-input dependency
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2025-05-20 21:42:05 +02:00
parent 3c636406af
commit 479cc1fa0f
5 changed files with 592 additions and 1193 deletions

View File

@ -1,4 +1,5 @@
import DeleteIcon from "@mui/icons-material/Delete";
import DownloadIcon from "@mui/icons-material/Download";
import {
Alert,
Button,
@ -9,21 +10,20 @@ import {
Tooltip,
Typography,
} from "@mui/material";
import DownloadIcon from "@mui/icons-material/Download";
import { DataGrid, GridColDef } from "@mui/x-data-grid";
import { filesize } from "filesize";
import { MuiFileInput } from "mui-file-input";
import React from "react";
import { IsoFile, IsoFilesApi } from "../api/IsoFilesApi";
import { ServerApi } from "../api/ServerApi";
import { useAlert } from "../hooks/providers/AlertDialogProvider";
import { useConfirm } from "../hooks/providers/ConfirmDialogProvider";
import { useLoadingMessage } from "../hooks/providers/LoadingMessageProvider";
import { useSnackbar } from "../hooks/providers/SnackbarProvider";
import { downloadBlob } from "../utils/FilesUtils";
import { AsyncWidget } from "../widgets/AsyncWidget";
import { FileInput } from "../widgets/forms/FileInput";
import { VirtWebPaper } from "../widgets/VirtWebPaper";
import { VirtWebRouteContainer } from "../widgets/VirtWebRouteContainer";
import { useConfirm } from "../hooks/providers/ConfirmDialogProvider";
import { downloadBlob } from "../utils/FilesUtils";
export function IsoFilesRoute(): React.ReactElement {
const [list, setList] = React.useState<IsoFile[] | undefined>();
@ -116,7 +116,7 @@ function UploadIsoFileCard(p: {
return (
<VirtWebPaper label="File upload">
<div style={{ display: "flex", alignItems: "center" }}>
<MuiFileInput
<FileInput
value={value}
onChange={handleChange}
style={{ flex: 1 }}

View File

@ -0,0 +1,75 @@
import AttachFileIcon from "@mui/icons-material/AttachFile";
import ClearIcon from "@mui/icons-material/Clear";
import {
IconButton,
InputAdornment,
OutlinedInputProps,
TextField,
TextFieldSlotsAndSlotProps,
Tooltip,
} from "@mui/material";
import { filesize } from "filesize";
import React from "react";
export function FileInput(
p: {
label?: string;
value: File | null;
onChange: (file: File | null) => void;
style?: React.CSSProperties;
} & TextFieldSlotsAndSlotProps<OutlinedInputProps>
): React.ReactElement {
const fileInput = React.useRef<HTMLInputElement>(null);
return (
<TextField
onClick={() => fileInput.current?.click()}
{...p}
value={""}
onChange={() => {}}
type="file"
slotProps={{
input: {
startAdornment: (
<>
<InputAdornment position="start">
<AttachFileIcon />
&nbsp;&nbsp;
{p.value ? p.value.name : "Insert a file"}
</InputAdornment>
</>
),
endAdornment: p.value ? (
<InputAdornment position="end">
{filesize(p.value.size)}
<Tooltip
title="Remove attached file"
onClick={(e) => e.stopPropagation()}
>
<IconButton
onClick={(e) => {
e.stopPropagation();
p.onChange(null);
}}
>
<ClearIcon />
</IconButton>
</Tooltip>
</InputAdornment>
) : undefined,
onChange: (e) => {
const files = (e.target as any).files;
p.onChange(files.length > 0 ? files[0] : null);
},
},
htmlInput: {
ref: fileInput,
style: { opacity: 0 },
},
}}
placeholder={"Insert a file"}
variant="outlined"
/>
);
}