Skip to content

Commit

Permalink
feat: 썸네일 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ymj07168 committed Oct 29, 2024
1 parent e09a634 commit 6755e4e
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/components/EditorPage/ThumbnailModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ThumbnailModal = ({
thumbnailImage,
isEdit,
}) => {
const [thumbnail, setThumbnail] = React.useState(null);
const [thumbnail, setThumbnail] = React.useState(thumbnailImage);
const isMobile = useMediaQuery("(max-width:550px)");

const handleFileChange = (event) => {
Expand All @@ -23,6 +23,13 @@ const ThumbnailModal = ({
document.getElementById("file-input").click();
};

const getThumbnailSrc = () => {
// File 타입인지 확인하여 URL을 생성하거나 기존 URL을 사용
return thumbnail instanceof File
? URL.createObjectURL(thumbnail)
: thumbnailImage;
};

return (
<Modal open={isOpen} onClose={onClose}>
<Box
Expand Down Expand Up @@ -58,23 +65,13 @@ const ThumbnailModal = ({
onChange={handleFileChange}
className="hidden"
/>
{/* 수정 중이고 썸네일 null인 경우 기존 썸네일 출력 */}
{isEdit && !thumbnail ? (
{thumbnail && (
<img
src={thumbnailImage}
src={getThumbnailSrc()}
alt="Thumbnail Preview"
className="my-3"
style={{ height: "200px", objectFit: "cover" }}
/>
) : (
thumbnail && (
<img
src={URL.createObjectURL(thumbnail)}
alt="Thumbnail Preview"
className="my-3"
style={{ height: "200px", objectFit: "cover" }}
/>
)
)}
<Button
variant="contained"
Expand Down

0 comments on commit 6755e4e

Please sign in to comment.