Skip to content

Commit 729aaa9

Browse files
committed
fix: 영상 업로드 progress 수정
1 parent d9153ae commit 729aaa9

File tree

3 files changed

+25
-52
lines changed

3 files changed

+25
-52
lines changed

src/routes/mission/$missionId/-components/MissionNotTried.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,10 @@ export default function MissionNotTried(props: MissionNotTriedProps) {
3333
const [state, setState] = useState<MissionState>("DEFAULT");
3434
const [capturedMedia, setCapturedMedia] = useState<CapturedMedia>(null);
3535
const [successAttemptId, setSuccessAttemptId] = useState<number | null>(null);
36-
const [currentUploadInfo, setCurrentUploadInfo] = useState<{
37-
isSuccess: boolean;
38-
attemptId: number | null;
39-
} | null>(null);
4036

4137
const fileInputRef = useRef<HTMLInputElement>(null);
4238

43-
const { uploadVideo, isUploading, progress } = useUploadAttemptVideo();
39+
const { uploadVideo, isUploading, percentage } = useUploadAttemptVideo();
4440

4541
const { mutateAsync: createAttemptMutate } = useMutation({
4642
mutationFn: (success: boolean) =>
@@ -88,20 +84,16 @@ export default function MissionNotTried(props: MissionNotTriedProps) {
8884
const newAttemptId = response.data?.missionAttemptId;
8985

9086
if (newAttemptId && capturedMedia?.file) {
91-
setCurrentUploadInfo({ isSuccess, attemptId: newAttemptId });
92-
9387
await uploadVideo(newAttemptId, capturedMedia.file, {
9488
onSuccess: () => {
9589
if (isSuccess) {
9690
setSuccessAttemptId(newAttemptId);
9791
}
9892
setState(isSuccess ? "SUCCESS" : "FAILED");
99-
setCurrentUploadInfo(null);
10093
},
10194
onError: (error) => {
10295
console.error("Upload failed:", error);
10396
setState("FAILED");
104-
setCurrentUploadInfo(null);
10597
},
10698
});
10799
} else {
@@ -110,7 +102,6 @@ export default function MissionNotTried(props: MissionNotTriedProps) {
110102
} catch (error) {
111103
console.error("Review failed:", error);
112104
setState(isSuccess ? "SUCCESS" : "FAILED");
113-
setCurrentUploadInfo(null);
114105
}
115106
};
116107

@@ -135,12 +126,7 @@ export default function MissionNotTried(props: MissionNotTriedProps) {
135126
className="hidden"
136127
/>
137128

138-
{isUploading && (
139-
<MissionVideoUploadOverlay
140-
progress={progress}
141-
isAttemptSuccess={currentUploadInfo?.isSuccess ?? false}
142-
/>
143-
)}
129+
{isUploading && <MissionVideoUploadOverlay percentage={percentage} />}
144130

145131
{(() => {
146132
switch (state) {

src/routes/mission/$missionId/-components/MissionVideoUploadOverlay.tsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
export default function MissionVideoUploadOverlay({
2-
progress,
3-
isAttemptSuccess,
2+
percentage,
43
}: {
5-
progress: { currentChunk: number; totalChunks: number; percentage: number };
6-
isAttemptSuccess: boolean;
4+
percentage: number;
75
}) {
86
return (
97
<div className="fixed inset-0 flex items-center justify-center bg-black/80 z-50">
10-
<div className="bg-neutral-900 rounded-2xl p-6 max-w-sm w-full mx-4">
8+
<div className="rounded-2xl p-6 max-w-sm w-full mx-4">
119
<div className="text-center">
12-
<h3 className="text-neutral-100 t-p-18-sb mb-4">
13-
{isAttemptSuccess
14-
? "추천 문제를 준비 중이에요"
15-
: "해설 영상을 불러오고 있어요"}
16-
</h3>
10+
<p className="text-neutral-100 t-p-16-m mb-4">
11+
영상을 업로드 중이에요.
12+
<br />
13+
화면 이동 시 영상이 저장되지 않아요.
14+
</p>
1715
<div className="space-y-4">
18-
<div className="w-full bg-neutral-800 rounded-full h-2">
16+
<div className="w-full bg-neutral-700 rounded-full h-2 shadow-md">
1917
<div
2018
className="bg-blue-500 h-2 rounded-full transition-all duration-300"
21-
style={{ width: `${progress.percentage}%` }}
19+
style={{ width: `${percentage}%` }}
2220
/>
2321
</div>
24-
<p className="text-neutral-400 t-p-14-m">
25-
{progress.currentChunk} / {progress.totalChunks}
26-
</p>
27-
<p className="text-neutral-300 t-p-12-m">
28-
{progress.percentage}% 완료
29-
</p>
22+
<p className="text-neutral-300 t-p-12-m">{percentage}% 완료</p>
3023
</div>
3124
</div>
3225
</div>

src/routes/mission/$missionId/-hooks/useUploadAttemptVideo.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,15 @@ import type { BodyType } from "@/utils/http";
1212

1313
const CHUNK_SIZE = 512 * 1024;
1414

15-
export interface UploadProgress {
16-
currentChunk: number;
17-
totalChunks: number;
18-
percentage: number;
19-
}
20-
2115
export interface UploadState {
2216
isUploading: boolean;
23-
progress: UploadProgress;
17+
percentage: number;
2418
uploadId?: string;
2519
error?: string;
2620
}
2721

2822
export interface UploadCallbacks {
29-
onProgress?: (progress: UploadProgress) => void;
23+
onProgress?: (percentage: number) => void;
3024
onSuccess?: (fileName: string) => void;
3125
onError?: (error: Error) => void;
3226
}
@@ -63,7 +57,7 @@ async function splitFileIntoChunks(
6357
export function useUploadAttemptVideo() {
6458
const [uploadState, setUploadState] = useState<UploadState>({
6559
isUploading: false,
66-
progress: { currentChunk: 0, totalChunks: 0, percentage: 0 },
60+
percentage: 0,
6761
});
6862

6963
const checkUploadStatusMutation = useMutation({
@@ -217,9 +211,11 @@ export function useUploadAttemptVideo() {
217211

218212
setUploadState((prev) => ({
219213
...prev,
220-
progress: { currentChunk: 0, totalChunks, percentage: 0 },
214+
percentage: 0,
221215
}));
222216

217+
let completedChunks = 0;
218+
223219
const uploadPromises = chunks.map(async (chunk, index) => {
224220
await uploadChunkMutation.mutateAsync({
225221
attemptId,
@@ -228,18 +224,16 @@ export function useUploadAttemptVideo() {
228224
chunk,
229225
});
230226

231-
const progress: UploadProgress = {
232-
currentChunk: index + 1,
233-
totalChunks,
234-
percentage: Math.round(((index + 1) / totalChunks) * 100),
235-
};
227+
completedChunks++;
228+
229+
const percentage = Math.round((completedChunks / totalChunks) * 100);
236230

237231
setUploadState((prev) => ({
238232
...prev,
239-
progress,
233+
percentage,
240234
}));
241235

242-
callbacks.onProgress?.(progress);
236+
callbacks.onProgress?.(percentage);
243237
});
244238

245239
await Promise.all(uploadPromises);
@@ -290,7 +284,7 @@ export function useUploadAttemptVideo() {
290284
checkUploadStatus,
291285
uploadState,
292286
isUploading: uploadState.isUploading,
293-
progress: uploadState.progress,
287+
percentage: uploadState.percentage,
294288
error: uploadState.error,
295289
uploadId: uploadState.uploadId,
296290
};

0 commit comments

Comments
 (0)