mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 18:29:15 +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>
|
<InputGroup>
|
||||||
<Input placeholder='Lesson name' type='text' {...register('title')} />
|
<Input placeholder='Lesson name' type='text' {...register('title')} />
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
<FormHelperText>e.g Introduction</FormHelperText>
|
|
||||||
<Text as='small' color='red.500'>
|
<Text as='small' color='red.500'>
|
||||||
{errors.title?.message}
|
{errors.title?.message}
|
||||||
</Text>
|
</Text>
|
||||||
|
<FormHelperText>e.g Introduction</FormHelperText>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
<FormControl isRequired id='description' isInvalid={!!errors.description}>
|
<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 { Flex, Box, Icon, Text, Button, Input, AspectRatio, useColorModeValue } from '@chakra-ui/react';
|
||||||
import { MdUpload } from 'react-icons/md';
|
import { MdUpload } from 'react-icons/md';
|
||||||
import { VideoSupportedFormatsEnum } from '@educt/enums';
|
import { VideoSupportedFormatsEnum } from '@educt/enums';
|
||||||
@ -10,6 +10,8 @@ type VideoUploaderPropsType = {
|
|||||||
|
|
||||||
const VideoUploader: React.FC<VideoUploaderPropsType> = ({ onChange, file }) => {
|
const VideoUploader: React.FC<VideoUploaderPropsType> = ({ onChange, file }) => {
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const videoRef = useRef<HTMLVideoElement>(null);
|
||||||
|
const [videoObjectUrl, setVideoObjectUrl] = useState<string | undefined>(undefined);
|
||||||
|
|
||||||
const onSelectFileHandler = () => {
|
const onSelectFileHandler = () => {
|
||||||
if (fileInputRef.current) {
|
if (fileInputRef.current) {
|
||||||
@ -25,25 +27,30 @@ const VideoUploader: React.FC<VideoUploaderPropsType> = ({ onChange, file }) =>
|
|||||||
if (files && files.length !== 0) {
|
if (files && files.length !== 0) {
|
||||||
const file = files[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 (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Input
|
{file && videoObjectUrl ? (
|
||||||
type='file'
|
|
||||||
ref={fileInputRef}
|
|
||||||
onChange={onChangeFileHandler}
|
|
||||||
display='none'
|
|
||||||
accept={Object.keys(VideoSupportedFormatsEnum)
|
|
||||||
.map(ext => `.${ext.toLowerCase()}`)
|
|
||||||
.join(', ')}
|
|
||||||
/>
|
|
||||||
{file ? (
|
|
||||||
<Box>
|
<Box>
|
||||||
<AspectRatio maxH='lg' mt='2'>
|
<AspectRatio maxH='lg' mt='2'>
|
||||||
<video controls style={{ borderRadius: '5px' }}>
|
<video ref={videoRef} controls style={{ borderRadius: '5px' }}>
|
||||||
<source src={URL.createObjectURL(file)} />
|
<source src={videoObjectUrl} />
|
||||||
</video>
|
</video>
|
||||||
</AspectRatio>
|
</AspectRatio>
|
||||||
<Button
|
<Button
|
||||||
@ -59,7 +66,7 @@ const VideoUploader: React.FC<VideoUploaderPropsType> = ({ onChange, file }) =>
|
|||||||
</Box>
|
</Box>
|
||||||
) : (
|
) : (
|
||||||
<Flex
|
<Flex
|
||||||
p='40px 0'
|
p='40px 10px'
|
||||||
textAlign={'center'}
|
textAlign={'center'}
|
||||||
borderRadius={'md'}
|
borderRadius={'md'}
|
||||||
flexDir={'column'}
|
flexDir={'column'}
|
||||||
@ -83,6 +90,20 @@ const VideoUploader: React.FC<VideoUploaderPropsType> = ({ onChange, file }) =>
|
|||||||
</Button>
|
</Button>
|
||||||
</Flex>
|
</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>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -67,7 +67,7 @@ export interface ILessonMaterial {
|
|||||||
export interface ILessonContent {
|
export interface ILessonContent {
|
||||||
id: number;
|
id: number;
|
||||||
lesson_id: string;
|
lesson_id: string;
|
||||||
video_url: string;
|
body: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICategory {
|
export interface ICategory {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { AxiosInstance } from 'axios';
|
import { AxiosInstance } from 'axios';
|
||||||
import { IApiRespose, ILesson } from '@educt/interfaces';
|
import { IApiRespose, ILesson } from '@educt/interfaces';
|
||||||
import { ApiServiceInstance } from './ApiService';
|
import { ApiServiceInstance } from './ApiService';
|
||||||
import type { LessonProgress } from '@educt/types';
|
import type { CreateLessonParamsType, LessonProgress } from '@educt/types';
|
||||||
|
|
||||||
class LessonService {
|
class LessonService {
|
||||||
public api: AxiosInstance;
|
public api: AxiosInstance;
|
||||||
@ -43,6 +43,15 @@ class LessonService {
|
|||||||
return result.data;
|
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
|
* 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;
|
image?: File | undefined;
|
||||||
status?: CourseStatusEnum | 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