import { useCourse } from '@components/Contexts/CourseContext' import { useOrg } from '@components/Contexts/OrgContext' import { getAPIUrl } from '@services/config/config' import { updateCourseThumbnail } from '@services/courses/courses' import { getCourseThumbnailMediaDirectory } from '@services/media/media' import { ArrowBigUpDash, UploadCloud } from 'lucide-react' import { useLHSession } from '@components/Contexts/LHSessionContext' import React from 'react' import { mutate } from 'swr' function ThumbnailUpdate() { const course = useCourse() as any const session = useLHSession() const org = useOrg() as any const [localThumbnail, setLocalThumbnail] = React.useState(null) as any const [isLoading, setIsLoading] = React.useState(false) as any const [error, setError] = React.useState('') as any const handleFileChange = async (event: any) => { const file = event.target.files[0] setLocalThumbnail(file) setIsLoading(true) const res = await updateCourseThumbnail( course.courseStructure.course_uuid, file, session.data?.tokens?.access_token ) mutate(`${getAPIUrl()}courses/${course.courseStructure.course_uuid}/meta`) // wait for 1 second to show loading animation await new Promise((r) => setTimeout(r, 1500)) if (res.success === false) { setError(res.HTTPmessage) } else { setIsLoading(false) setError('') } } return (