Skip to content

Commit bdc8de1

Browse files
committed
fix: 파일 선택기에서 선택한 이미지의 미리보기가 보이지 않는 문제 수정
1 parent 8f51361 commit bdc8de1

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

apps/pyconkr-participant-portal/src/components/elements/public_file_selector.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as Common from "@frontend/common";
22
import { PermMedia } from "@mui/icons-material";
3-
import { Box, Button, CircularProgress, FormControl, InputLabel, MenuItem, Select, SelectProps, Stack, useMediaQuery } from "@mui/material";
3+
import { Box, Button, CircularProgress, FormControl, InputLabel, MenuItem, Select, SelectProps, Stack, styled, useMediaQuery } from "@mui/material";
44
import { ErrorBoundary, Suspense } from "@suspensive/react";
55
import * as React from "react";
66

7-
import { Fieldset } from "./fieldset";
87
import { useAppContext } from "../../contexts/app_context";
98
import { PublicFileUploadDialog } from "../dialogs/public_file_upload";
9+
import { Fieldset } from "./fieldset";
1010

1111
type PublicFileSelectorProps = SelectProps<string | null | undefined> & {
1212
setFileIdAsValue?: (fileId?: string | null) => void;
@@ -17,18 +17,29 @@ const ImageFallback: React.FC<{ language: "ko" | "en" }> = ({ language }) => (
1717
);
1818

1919
type PublicFileSelectorState = {
20+
fileId?: string | null;
2021
openUploadDialog?: boolean;
2122
};
2223

24+
const ScaledFallbackImage = styled(Common.Components.FallbackImage)({
25+
width: "100%",
26+
maxWidth: "20rem",
27+
objectFit: "contain",
28+
});
29+
2330
export const PublicFileSelector: React.FC<PublicFileSelectorProps> = ErrorBoundary.with(
2431
{ fallback: Common.Components.ErrorFallback },
25-
Suspense.with({ fallback: <CircularProgress /> }, ({ setFileIdAsValue, ...props }) => {
32+
Suspense.with({ fallback: <CircularProgress /> }, ({ onChange, setFileIdAsValue, ...props }) => {
2633
const [selectorState, setSelectorState] = React.useState<PublicFileSelectorState>({});
2734
const { language } = useAppContext();
2835
const participantPortalClient = Common.Hooks.BackendParticipantPortalAPI.useParticipantPortalClient();
2936
const { data } = Common.Hooks.BackendParticipantPortalAPI.usePublicFilesQuery(participantPortalClient);
3037
const isMobile = useMediaQuery((theme) => theme.breakpoints.down("md"));
3138

39+
const setSelectedFile: SelectProps<string | null | undefined>["onChange"] = (event, child) => {
40+
setSelectorState((ps) => ({ ...ps, fileId: event.target.value }));
41+
onChange?.(event, child);
42+
};
3243
const openUploadDialog = () => setSelectorState((ps) => ({ ...ps, openUploadDialog: true }));
3344
const closeUploadDialog = () => setSelectorState((ps) => ({ ...ps, openUploadDialog: false }));
3445

@@ -42,11 +53,11 @@ export const PublicFileSelector: React.FC<PublicFileSelectorProps> = ErrorBounda
4253
<PublicFileUploadDialog open={!!selectorState.openUploadDialog} onClose={closeUploadDialog} setFileIdAsValue={setFileIdAsValue} />
4354
<Fieldset legend={props.label?.toString() || ""}>
4455
<Stack direction="column" spacing={2} alignItems="center" justifyContent="center">
45-
<Common.Components.FallbackImage src={selectedFile?.file} alt="Selected File" errorFallback={<ImageFallback language={language} />} />
56+
<ScaledFallbackImage src={selectedFile?.file} alt="Selected File" loading="lazy" errorFallback={<ImageFallback language={language} />} />
4657
<Stack direction={isMobile ? "column" : "row"} spacing={2} sx={{ width: "100%" }} alignItems="center">
4758
<FormControl fullWidth>
4859
<InputLabel id="public-file-label">{props.label}</InputLabel>
49-
<Select labelId="public-file-label" {...props}>
60+
<Select labelId="public-file-label" onChange={setSelectedFile} {...props}>
5061
{files.map((file) => (
5162
<MenuItem key={file.id} value={file.id} children={file.name} />
5263
))}

0 commit comments

Comments
 (0)