mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 18:29:15 +03:00
fix: some fixed
This commit is contained in:
parent
47e16e06de
commit
8fb9a2f787
@ -25,11 +25,11 @@ const App = () => {
|
|||||||
useSocketEvent('disconnect', () => console.info('[WebSocket]: Disconnected.'));
|
useSocketEvent('disconnect', () => console.info('[WebSocket]: Disconnected.'));
|
||||||
useSocketEvent('connect_error', err => console.error(err));
|
useSocketEvent('connect_error', err => console.error(err));
|
||||||
useSocketEvent('user:session', data => {
|
useSocketEvent('user:session', data => {
|
||||||
console.log(data);
|
|
||||||
if (socket) {
|
if (socket) {
|
||||||
const { sessionId, userId } = data;
|
const { sessionId, userId } = data;
|
||||||
socket.auth = { sessionId };
|
socket.auth = { sessionId };
|
||||||
window.localStorage.setItem('sessionId', sessionId);
|
window.localStorage.setItem('sessionId', sessionId);
|
||||||
|
// TODO fix types
|
||||||
socket.userId = userId;
|
socket.userId = userId;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -60,8 +60,8 @@ const FileSelect: React.FC<FileSelectPropsType> = ({ onChange, file, supportedFo
|
|||||||
</Text>
|
</Text>
|
||||||
</Text>
|
</Text>
|
||||||
) : (
|
) : (
|
||||||
<Text fontWeight='normal' color='gray'>
|
<Text fontWeight='normal' color='gray.500'>
|
||||||
Choose a file...
|
Select new file
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
{supportedFormats && (
|
{supportedFormats && (
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import * as helpers from '@educt/helpers';
|
import * as helpers from '@educt/helpers';
|
||||||
import { Stack, Flex, Box, Icon, Text, Input, IconButton, Button } from '@chakra-ui/react';
|
import { Stack, Flex, Box, Icon, Text, Input, IconButton, Button, useColorModeValue } from '@chakra-ui/react';
|
||||||
import { MdAttachFile, MdOutlineFilePresent } from 'react-icons/md';
|
import { MdAttachFile, MdOutlineFilePresent } from 'react-icons/md';
|
||||||
import { CloseIcon } from '@chakra-ui/icons';
|
import { CloseIcon } from '@chakra-ui/icons';
|
||||||
|
|
||||||
@ -31,7 +31,13 @@ const FileContent: React.FC<{ name: string; size: number }> = ({ name, size }) =
|
|||||||
);
|
);
|
||||||
|
|
||||||
const FileWrapper: React.FC = ({ children }) => (
|
const FileWrapper: React.FC = ({ children }) => (
|
||||||
<Flex alignItems={'center'} justifyContent={'space-between'} p='3' bg={'gray.50'} borderRadius={'lg'}>
|
<Flex
|
||||||
|
alignItems={'center'}
|
||||||
|
justifyContent={'space-between'}
|
||||||
|
p='3'
|
||||||
|
bg={useColorModeValue('gray.50', 'gray.700')}
|
||||||
|
borderRadius={'lg'}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -60,6 +60,13 @@ const Layout: React.FC<LayoutPropsType> = ({ children, roles }) => {
|
|||||||
}
|
}
|
||||||
}, [socket]);
|
}, [socket]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit online status of user
|
||||||
|
*/
|
||||||
|
useEffect(() => {
|
||||||
|
socket?.emit('user:status');
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Header />
|
<Header />
|
||||||
|
|||||||
@ -13,10 +13,7 @@ import { SocketContext } from '@educt/contexts';
|
|||||||
type LogoutResultDataType = Record<string, never>;
|
type LogoutResultDataType = Record<string, never>;
|
||||||
|
|
||||||
const useLogout = () => {
|
const useLogout = () => {
|
||||||
const {
|
const { authStore } = useRootStore();
|
||||||
authStore,
|
|
||||||
userStore: { me },
|
|
||||||
} = useRootStore();
|
|
||||||
const { socket } = useContext(SocketContext);
|
const { socket } = useContext(SocketContext);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
@ -24,7 +21,6 @@ const useLogout = () => {
|
|||||||
|
|
||||||
const logout = async () => {
|
const logout = async () => {
|
||||||
try {
|
try {
|
||||||
const sessionId = window.localStorage.getItem('sessionId');
|
|
||||||
const result = await authStore.logout();
|
const result = await authStore.logout();
|
||||||
|
|
||||||
history.push('/auth');
|
history.push('/auth');
|
||||||
@ -33,13 +29,12 @@ const useLogout = () => {
|
|||||||
/**
|
/**
|
||||||
* Destroy session
|
* Destroy session
|
||||||
*/
|
*/
|
||||||
if (sessionId) {
|
|
||||||
if (socket) {
|
if (socket) {
|
||||||
socket.auth = { sessionId: undefined };
|
|
||||||
// socket.emit('user:logout', { sessionId });
|
|
||||||
socket.disconnect();
|
|
||||||
}
|
|
||||||
window.localStorage.removeItem('sessionId');
|
window.localStorage.removeItem('sessionId');
|
||||||
|
|
||||||
|
socket.auth = { sessionId: undefined };
|
||||||
|
socket.emit('user:logout');
|
||||||
|
socket.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.data;
|
return result.data;
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import { useHistory, useParams } from 'react-router-dom';
|
|||||||
import { useFetchCourse } from '@educt/hooks/queries';
|
import { useFetchCourse } from '@educt/hooks/queries';
|
||||||
import { useRootStore } from '@educt/hooks/useRootStore';
|
import { useRootStore } from '@educt/hooks/useRootStore';
|
||||||
import { Helmet } from 'react-helmet';
|
import { Helmet } from 'react-helmet';
|
||||||
|
import { EditButton } from '@educt/components/Buttons';
|
||||||
|
|
||||||
const CoursePage: React.FC<IPageProps> = () => {
|
const CoursePage: React.FC<IPageProps> = () => {
|
||||||
const {
|
const {
|
||||||
@ -46,6 +47,8 @@ const CoursePage: React.FC<IPageProps> = () => {
|
|||||||
|
|
||||||
const handleWatchCourse = () => history.push(`/lesson/${course.lessons[0].id}`);
|
const handleWatchCourse = () => history.push(`/lesson/${course.lessons[0].id}`);
|
||||||
|
|
||||||
|
const handleEditCourse = () => history.push(`/courses/edit/${course.id}`);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageWrapper maxW='1200px'>
|
<PageWrapper maxW='1200px'>
|
||||||
<Helmet>
|
<Helmet>
|
||||||
@ -67,6 +70,8 @@ const CoursePage: React.FC<IPageProps> = () => {
|
|||||||
<Box>
|
<Box>
|
||||||
<Flex justifyContent={'space-between'} alignItems={'center'} mb='2'>
|
<Flex justifyContent={'space-between'} alignItems={'center'} mb='2'>
|
||||||
<Text fontSize={'sm'}>Last update: {new Date(course.updated_at).toLocaleDateString()}</Text>
|
<Text fontSize={'sm'}>Last update: {new Date(course.updated_at).toLocaleDateString()}</Text>
|
||||||
|
<Box>
|
||||||
|
{(me.isAdmin || me.isTeacher) && <EditButton onClick={handleEditCourse} mr='2' />}
|
||||||
<Button
|
<Button
|
||||||
isDisabled={!isCourseAvailable}
|
isDisabled={!isCourseAvailable}
|
||||||
onClick={handleWatchCourse}
|
onClick={handleWatchCourse}
|
||||||
@ -76,6 +81,7 @@ const CoursePage: React.FC<IPageProps> = () => {
|
|||||||
>
|
>
|
||||||
Watch
|
Watch
|
||||||
</Button>
|
</Button>
|
||||||
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
<CourseBackgroundImage bg={course.color?.hex} src={course.image?.url} />
|
<CourseBackgroundImage bg={course.color?.hex} src={course.image?.url} />
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@ -41,6 +41,7 @@ import { useState } from 'react';
|
|||||||
import { useColorModeValue } from '@chakra-ui/react';
|
import { useColorModeValue } from '@chakra-ui/react';
|
||||||
import { useRootStore } from '@educt/hooks/useRootStore';
|
import { useRootStore } from '@educt/hooks/useRootStore';
|
||||||
import { CourseServiceInstance } from '@educt/services';
|
import { CourseServiceInstance } from '@educt/services';
|
||||||
|
import { EditButton } from '@educt/components/Buttons';
|
||||||
|
|
||||||
export const CourseHeader: React.FC<FlexProps> = props => (
|
export const CourseHeader: React.FC<FlexProps> = props => (
|
||||||
<Flex justifyContent='space-between' flexDir={{ base: 'column', xl: 'row' }} {...props}>
|
<Flex justifyContent='space-between' flexDir={{ base: 'column', xl: 'row' }} {...props}>
|
||||||
@ -62,7 +63,10 @@ export const CourseHeading: React.FC<ICourseHeadingProps> = props => {
|
|||||||
{title}
|
{title}
|
||||||
</Heading>
|
</Heading>
|
||||||
<Flex mt='3' alignItems={'center'}>
|
<Flex mt='3' alignItems={'center'}>
|
||||||
<Text fontSize='sm'>{teacher.fullname}</Text> •
|
<Text fontSize='sm'>
|
||||||
|
{teacher.fullname}
|
||||||
|
•
|
||||||
|
</Text>
|
||||||
<Tag size='sm' variant='solid' bg={category.color?.hex}>
|
<Tag size='sm' variant='solid' bg={category.color?.hex}>
|
||||||
{category.title}
|
{category.title}
|
||||||
</Tag>
|
</Tag>
|
||||||
|
|||||||
@ -40,6 +40,8 @@ const CourseItem: React.FC<CourseItemPropsType> = ({ course, onDelete, onSetStat
|
|||||||
const { colorMode } = useColorMode();
|
const { colorMode } = useColorMode();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
|
const handleEditCourse = () => history.push(`/courses/edit/${course.id}`);
|
||||||
|
|
||||||
if (me === null) return null;
|
if (me === null) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -58,7 +60,7 @@ const CourseItem: React.FC<CourseItemPropsType> = ({ course, onDelete, onSetStat
|
|||||||
_active={{ backgroundColor: colorMode === 'dark' ? 'gray.600' : 'gray.200' }}
|
_active={{ backgroundColor: colorMode === 'dark' ? 'gray.600' : 'gray.200' }}
|
||||||
/>
|
/>
|
||||||
<MenuList>
|
<MenuList>
|
||||||
<MenuItem onClick={() => history.push(`/courses/edit/${course.id}`)} icon={<EditIcon />}>
|
<MenuItem onClick={handleEditCourse} icon={<EditIcon />}>
|
||||||
Edit
|
Edit
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{(() => {
|
{(() => {
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import ReactPlayer from 'react-player';
|
|||||||
import { MdOutlineCircle, MdCheckCircle, MdOutlineFilePresent, MdSkipNext, MdSkipPrevious } from 'react-icons/md';
|
import { MdOutlineCircle, MdCheckCircle, MdOutlineFilePresent, MdSkipNext, MdSkipPrevious } from 'react-icons/md';
|
||||||
import LoadingPage from '@educt/components/LoadingPage';
|
import LoadingPage from '@educt/components/LoadingPage';
|
||||||
import { PageContent, PageHeading, PageWrapper } from '@educt/components/PageElements';
|
import { PageContent, PageHeading, PageWrapper } from '@educt/components/PageElements';
|
||||||
import { EditIcon } from '@chakra-ui/icons';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Types
|
* Types
|
||||||
@ -45,6 +44,7 @@ import { useFetchLessonProgress } from '@educt/hooks/queries/lesson/useFetchLess
|
|||||||
* Services
|
* Services
|
||||||
*/
|
*/
|
||||||
import { LessonServiceInstance } from '@educt/services';
|
import { LessonServiceInstance } from '@educt/services';
|
||||||
|
import { EditButton } from '@educt/components/Buttons';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lesson Page
|
* Lesson Page
|
||||||
@ -145,11 +145,7 @@ const LessonPage: React.FC<IPageProps> = () => {
|
|||||||
<PageHeading heading={lesson.title}>
|
<PageHeading heading={lesson.title}>
|
||||||
<Flex mt='3' alignItems={'center'} justifyContent={'space-between'}>
|
<Flex mt='3' alignItems={'center'} justifyContent={'space-between'}>
|
||||||
<Text fontSize={'sm'}>~{moment.duration(lesson.duration, 'minutes').humanize()}</Text>
|
<Text fontSize={'sm'}>~{moment.duration(lesson.duration, 'minutes').humanize()}</Text>
|
||||||
{(me.isAdmin || me.isTeacher) && (
|
{(me.isAdmin || me.isTeacher) && <EditButton onClick={handleEditLesson} />}
|
||||||
<Button onClick={handleEditLesson} leftIcon={<EditIcon />} variant={'outline'} size='sm'>
|
|
||||||
Edit
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Flex>
|
</Flex>
|
||||||
</PageHeading>
|
</PageHeading>
|
||||||
<PageContent>
|
<PageContent>
|
||||||
|
|||||||
@ -41,7 +41,7 @@ const MainPage: React.FC<IPageProps> = () => {
|
|||||||
*/
|
*/
|
||||||
useSocketEvent('user:online', online => setOnline(online));
|
useSocketEvent('user:online', online => setOnline(online));
|
||||||
|
|
||||||
useSocketEvent('user:connected', user => console.table(user));
|
// useSocketEvent('user:connected', user => console.table(user));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (stat) {
|
if (stat) {
|
||||||
@ -69,7 +69,7 @@ const MainPage: React.FC<IPageProps> = () => {
|
|||||||
<StatContent>
|
<StatContent>
|
||||||
<StatNumber>
|
<StatNumber>
|
||||||
<Link as={ReactRouterLink} to='/messages'>
|
<Link as={ReactRouterLink} to='/messages'>
|
||||||
1
|
0
|
||||||
</Link>
|
</Link>
|
||||||
</StatNumber>
|
</StatNumber>
|
||||||
<StatIcon icon={MdOutlineMessage} />
|
<StatIcon icon={MdOutlineMessage} />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user