front 작업 중 .
This commit is contained in:
1 parent
ecbd81d091
commit
24d61f925a
8 files changed
+796
-124
No files matched your search
@@ -1,10 +1,11 @@
|
||||
|
||||
import React, { useRef } from 'react';
|
||||
import { ImageItem } from '../../types/api';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { ImageItem, ImageUrlItem } from '../../types/api';
|
||||
import { uploadImages } from '../../utils/api';
|
||||
|
||||
interface AssetManagementContentProps {
|
||||
onBack: () => void;
|
||||
onNext: () => void;
|
||||
onNext: (imageTaskId: string) => void;
|
||||
imageList: ImageItem[];
|
||||
onRemoveImage: (index: number) => void;
|
||||
onAddImages: (files: File[]) => void;
|
||||
@@ -19,11 +20,42 @@ const AssetManagementContent: React.FC<AssetManagementContentProps> = ({
|
||||
}) => {
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const imageListRef = useRef<HTMLDivElement>(null);
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
const [uploadError, setUploadError] = useState<string | null>(null);
|
||||
|
||||
const getImageSrc = (item: ImageItem): string => {
|
||||
return item.type === 'url' ? item.url : item.preview;
|
||||
};
|
||||
|
||||
const handleNextWithUpload = async () => {
|
||||
if (imageList.length === 0) return;
|
||||
|
||||
setIsUploading(true);
|
||||
setUploadError(null);
|
||||
|
||||
try {
|
||||
// URL 이미지와 파일 이미지 분리
|
||||
const urlImages: ImageUrlItem[] = imageList
|
||||
.filter((item: ImageItem): item is ImageItem & { type: 'url' } => item.type === 'url')
|
||||
.map((item) => ({ url: item.url }));
|
||||
|
||||
const fileImages: File[] = imageList
|
||||
.filter((item: ImageItem): item is ImageItem & { type: 'file' } => item.type === 'file')
|
||||
.map((item) => item.file);
|
||||
|
||||
// 이미지가 하나라도 있으면 업로드
|
||||
if (urlImages.length > 0 || fileImages.length > 0) {
|
||||
const response = await uploadImages(urlImages, fileImages);
|
||||
onNext(response.task_id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Image upload failed:', error);
|
||||
setUploadError(error instanceof Error ? error.message : '이미지 업로드에 실패했습니다.');
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleImageListWheel = (e: React.WheelEvent) => {
|
||||
const el = imageListRef.current;
|
||||
if (!el) return;
|
||||
@@ -172,12 +204,15 @@ const AssetManagementContent: React.FC<AssetManagementContentProps> = ({
|
||||
|
||||
{/* Bottom Button */}
|
||||
<div className="bottom-button-container">
|
||||
{uploadError && (
|
||||
<p className="text-red-500 text-sm mb-2">{uploadError}</p>
|
||||
)}
|
||||
<button
|
||||
onClick={onNext}
|
||||
disabled={imageList.length === 0}
|
||||
className={`btn-primary ${imageList.length === 0 ? 'disabled' : ''}`}
|
||||
onClick={handleNextWithUpload}
|
||||
disabled={imageList.length === 0 || isUploading}
|
||||
className={`btn-primary ${imageList.length === 0 || isUploading ? 'disabled' : ''}`}
|
||||
>
|
||||
다음 단계
|
||||
{isUploading ? '업로드 중...' : '다음 단계'}
|
||||
</button>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
Reference in new issue
Block a user