- {uploadingEditVideo ? "Uploading…" : "Click to upload"}
+ {uploadingEditVideo
+ ? editVideoProgress.message || "Uploading…"
+ : "Click to upload"}
{" "}
video from your computer
@@ -974,6 +991,12 @@ export function CourseModuleDetailPage() {
+ {editVideoProgress.phase !== "idle" ? (
+
+ ) : null}
setEditVideoUrl(e.target.value)}
diff --git a/src/pages/content-management/SpeakingPage.tsx b/src/pages/content-management/SpeakingPage.tsx
index b427e6d..951c574 100644
--- a/src/pages/content-management/SpeakingPage.tsx
+++ b/src/pages/content-management/SpeakingPage.tsx
@@ -21,7 +21,10 @@ import {
getQuestionSets,
updateQuestion,
} from "../../api/courses.api"
-import { resolveFileUrl, uploadAudioFile, uploadImageFile, uploadVideoFile } from "../../api/files.api"
+import { resolveFileUrl, uploadAudioFile, uploadImageFile } from "../../api/files.api"
+import { VideoUploadProgressBar } from "../../components/video-upload/VideoUploadProgressBar"
+import { useVideoUpload } from "../../hooks/useVideoUpload"
+import { vimeoResultToStoredUrl } from "../../lib/video-upload/upload-video"
import { SpinnerIcon } from "../../components/ui/spinner-icon"
import {
DropdownMenu,
@@ -115,18 +118,6 @@ function normalizeObjectKey(value: string) {
return trimmed
}
-/** Prefer direct storage URL; for Vimeo pipeline match SubCourseContentPage player URL shape. */
-function introVideoUrlFromUploadResponse(data: { url?: string; embed_url?: string } | undefined): string | null {
- if (!data) return null
- const pageUrl = data.url?.trim()
- const embedUrl = data.embed_url?.trim()
- if (embedUrl) {
- const hashFromUrl = pageUrl ? pageUrl.split("/").filter(Boolean).at(-1) : undefined
- return hashFromUrl ? `${embedUrl}?h=${hashFromUrl}` : embedUrl
- }
- return pageUrl || null
-}
-
function toVimeoEmbedUrl(rawUrl: string): string | null {
try {
const parsed = new URL(rawUrl.trim())
@@ -172,7 +163,12 @@ export function SpeakingPage() {
const [setTitle, setSetTitle] = useState("")
const [setDescription, setSetDescription] = useState("")
const [introVideoUrl, setIntroVideoUrl] = useState("")
- const [uploadingIntroVideo, setUploadingIntroVideo] = useState(false)
+ const {
+ upload: uploadIntroVideo,
+ cancel: cancelIntroVideo,
+ progress: introVideoProgress,
+ isBusy: uploadingIntroVideo,
+ } = useVideoUpload()
const introVideoFileInputRef = useRef(null)
const [subCourseId, setSubCourseId] = useState("")
const [subCourseOptions, setSubCourseOptions] = useState([])
@@ -605,21 +601,19 @@ export function SpeakingPage() {
event.target.value = ""
if (!file) return
- setUploadingIntroVideo(true)
try {
- const uploadRes = await uploadVideoFile(file, {
+ const res = await uploadIntroVideo(file, {
title: setTitle.trim() || file.name.replace(/\.[^.]+$/, "") || "Speaking intro",
description: setDescription.trim() || undefined,
})
- const finalUrl = introVideoUrlFromUploadResponse(uploadRes.data?.data)
- if (!finalUrl) throw new Error("Missing uploaded video url")
- setIntroVideoUrl(finalUrl)
- toast.success("Intro video uploaded", { description: "The URL has been filled in for you." })
+ if (res) {
+ setIntroVideoUrl(vimeoResultToStoredUrl(res))
+ toast.success("Intro video uploaded", { description: "The URL has been filled in for you." })
+ }
} catch (error) {
+ if (error instanceof DOMException && error.name === "AbortError") return
console.error("Failed to upload intro video:", error)
notifyApiError(error, "Failed to upload intro video")
- } finally {
- setUploadingIntroVideo(false)
}
}
@@ -1990,7 +1984,9 @@ export function SpeakingPage() {
) : (
)}
- {uploadingIntroVideo ? "Uploading…" : "Upload video from computer"}
+ {uploadingIntroVideo
+ ? introVideoProgress.message || "Uploading…"
+ : "Upload video from computer"}
{introVideoUrl.trim() ? (
) : null}
+ {introVideoProgress.phase !== "idle" ? (
+
+ ) : null}
- Paste a link or upload from your computer; uploads use the same file service as elsewhere. Optional, not tied to sub-course video rows.
+ Paste a Vimeo link or upload from your computer. Optional, not tied to sub-course video rows.
{introVideoPreview ? (
diff --git a/src/pages/content-management/SubCourseContentPage.tsx b/src/pages/content-management/SubCourseContentPage.tsx
index 8f1a742..ae3e466 100644
--- a/src/pages/content-management/SubCourseContentPage.tsx
+++ b/src/pages/content-management/SubCourseContentPage.tsx
@@ -19,7 +19,9 @@ import {
getVimeoSample,
} from "../../api/courses.api"
import { getRatings } from "../../api/ratings.api"
-import { uploadVideoFile } from "../../api/files.api"
+import { VideoUploadProgressBar } from "../../components/video-upload/VideoUploadProgressBar"
+import { useVideoUpload } from "../../hooks/useVideoUpload"
+import { vimeoResultToStoredUrl } from "../../lib/video-upload/upload-video"
import type {
SubCourse,
QuestionSet,
@@ -90,6 +92,12 @@ export function SubModuleContentPage() {
const [videoVisibility, setVideoVisibility] = useState("PUBLISHED")
const [videoStatus, setVideoStatus] = useState("PUBLISHED")
const [videoDisplayOrder, setVideoDisplayOrder] = useState(1)
+ const {
+ upload: uploadNewVideo,
+ cancel: cancelNewVideo,
+ progress: newVideoProgress,
+ isBusy: uploadingNewVideo,
+ } = useVideoUpload()
// Vimeo preview state
const [showPreviewModal, setShowPreviewModal] = useState(false)
@@ -287,21 +295,16 @@ export function SubModuleContentPage() {
setSaving(true)
setSaveError(null)
try {
- const uploadRes = await uploadVideoFile(videoFile, {
- title: videoTitle.trim(),
- description: videoDescription.trim(),
+ const uploadResult = await uploadNewVideo(videoFile, {
+ title: videoTitle.trim() || videoFile.name,
+ description: videoDescription.trim() || undefined,
})
+ if (!uploadResult) {
+ setSaving(false)
+ return
+ }
- // Per backend guide, use embed_url as the video_url reference.
- const embedUrl = uploadRes.data?.data?.embed_url?.trim()
- const vimeoUrl = uploadRes.data?.data?.url?.trim()
- if (!embedUrl) throw new Error("Missing uploaded video embed_url")
-
- // Backend requires: https://player.vimeo.com/video/?h=
- // where is the last path segment from `url` (e.g. https://vimeo.com//)
- const hashFromUrl = vimeoUrl ? vimeoUrl.split("/").filter(Boolean).at(-1) : undefined
- const finalVideoUrl = hashFromUrl ? `${embedUrl}?h=${hashFromUrl}` : embedUrl
-
+ const finalVideoUrl = vimeoResultToStoredUrl(uploadResult)
const finalTitle = videoTitle.trim() || videoFile.name
await createCourseVideo({
@@ -1108,18 +1111,30 @@ export function SubModuleContentPage() {