mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 10:19:22 +03:00
fix: fixed updating video renred on change input
This commit is contained in:
parent
03c8e3b8cc
commit
10d2cf3782
@ -48,10 +48,10 @@ const LessonForm: React.FC<LessonFormPropsType> = ({ onSubmit, buttonLabel, isLo
|
||||
<InputGroup>
|
||||
<Input placeholder='Lesson name' type='text' {...register('title')} />
|
||||
</InputGroup>
|
||||
<FormHelperText>e.g Introduction</FormHelperText>
|
||||
<Text as='small' color='red.500'>
|
||||
{errors.title?.message}
|
||||
</Text>
|
||||
<FormHelperText>e.g Introduction</FormHelperText>
|
||||
</FormControl>
|
||||
|
||||
<FormControl isRequired id='description' isInvalid={!!errors.description}>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import React, { useRef } from 'react';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { Flex, Box, Icon, Text, Button, Input, AspectRatio, useColorModeValue } from '@chakra-ui/react';
|
||||
import { MdUpload } from 'react-icons/md';
|
||||
import { VideoSupportedFormatsEnum } from '@educt/enums';
|
||||
@ -10,6 +10,8 @@ type VideoUploaderPropsType = {
|
||||
|
||||
const VideoUploader: React.FC<VideoUploaderPropsType> = ({ onChange, file }) => {
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const videoRef = useRef<HTMLVideoElement>(null);
|
||||
const [videoObjectUrl, setVideoObjectUrl] = useState<string | undefined>(undefined);
|
||||
|
||||
const onSelectFileHandler = () => {
|
||||
if (fileInputRef.current) {
|
||||
@ -25,25 +27,30 @@ const VideoUploader: React.FC<VideoUploaderPropsType> = ({ onChange, file }) =>
|
||||
if (files && files.length !== 0) {
|
||||
const file = files[0];
|
||||
|
||||
file.type.match('video.*') && onChange(file);
|
||||
if (file.type.match('video.*')) {
|
||||
onChange(file);
|
||||
setVideoObjectUrl(prevUrl => {
|
||||
prevUrl && URL.revokeObjectURL(prevUrl);
|
||||
const newUrl = URL.createObjectURL(file);
|
||||
return newUrl;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (videoRef.current) {
|
||||
videoRef.current.load();
|
||||
}
|
||||
}, [videoObjectUrl]);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Input
|
||||
type='file'
|
||||
ref={fileInputRef}
|
||||
onChange={onChangeFileHandler}
|
||||
display='none'
|
||||
accept={Object.keys(VideoSupportedFormatsEnum)
|
||||
.map(ext => `.${ext.toLowerCase()}`)
|
||||
.join(', ')}
|
||||
/>
|
||||
{file ? (
|
||||
{file && videoObjectUrl ? (
|
||||
<Box>
|
||||
<AspectRatio maxH='lg' mt='2'>
|
||||
<video controls style={{ borderRadius: '5px' }}>
|
||||
<source src={URL.createObjectURL(file)} />
|
||||
<video ref={videoRef} controls style={{ borderRadius: '5px' }}>
|
||||
<source src={videoObjectUrl} />
|
||||
</video>
|
||||
</AspectRatio>
|
||||
<Button
|
||||
@ -59,7 +66,7 @@ const VideoUploader: React.FC<VideoUploaderPropsType> = ({ onChange, file }) =>
|
||||
</Box>
|
||||
) : (
|
||||
<Flex
|
||||
p='40px 0'
|
||||
p='40px 10px'
|
||||
textAlign={'center'}
|
||||
borderRadius={'md'}
|
||||
flexDir={'column'}
|
||||
@ -83,6 +90,20 @@ const VideoUploader: React.FC<VideoUploaderPropsType> = ({ onChange, file }) =>
|
||||
</Button>
|
||||
</Flex>
|
||||
)}
|
||||
<Input
|
||||
type='file'
|
||||
ref={fileInputRef}
|
||||
onChange={onChangeFileHandler}
|
||||
maxW={'0'}
|
||||
h='0'
|
||||
display={'block'}
|
||||
opacity={'0'}
|
||||
ml='auto'
|
||||
mr='auto'
|
||||
accept={Object.keys(VideoSupportedFormatsEnum)
|
||||
.map(ext => `.${ext.toLowerCase()}`)
|
||||
.join(', ')}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
@ -67,7 +67,7 @@ export interface ILessonMaterial {
|
||||
export interface ILessonContent {
|
||||
id: number;
|
||||
lesson_id: string;
|
||||
video_url: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
export interface ICategory {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { AxiosInstance } from 'axios';
|
||||
import { IApiRespose, ILesson } from '@educt/interfaces';
|
||||
import { ApiServiceInstance } from './ApiService';
|
||||
import type { LessonProgress } from '@educt/types';
|
||||
import type { CreateLessonParamsType, LessonProgress } from '@educt/types';
|
||||
|
||||
class LessonService {
|
||||
public api: AxiosInstance;
|
||||
@ -43,6 +43,15 @@ class LessonService {
|
||||
return result.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new lesson
|
||||
*
|
||||
* @param data Lesson data for creating
|
||||
*/
|
||||
public async create(data: CreateLessonParamsType): Promise<IApiRespose<ILesson>> {
|
||||
console.log(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete lesson by id
|
||||
*
|
||||
|
||||
9
src/types/index.d.ts
vendored
9
src/types/index.d.ts
vendored
@ -160,3 +160,12 @@ export type UpdateCourseParamsType = {
|
||||
image?: File | undefined;
|
||||
status?: CourseStatusEnum | undefined;
|
||||
};
|
||||
|
||||
export type CreateLessonParamsType = {
|
||||
title: string;
|
||||
description: string;
|
||||
duration: string;
|
||||
course_id: string;
|
||||
video: File;
|
||||
materials?: File[] | undefined;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user