Skip to content

Commit 72f5ae5

Browse files
committed
CoursesList: анимация загрузки
1 parent dcfd14c commit 72f5ae5

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

hwproj.front/src/components/Courses/Courses.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,6 @@ export default class Courses extends React.Component<Props, ICoursesState> {
3838
const {isLoaded, allCourses, myCourses, tabValue} = this.state;
3939
const {navigate} = this.props.navigate;
4040

41-
if (!isLoaded) {
42-
return (
43-
<div className="container">
44-
<DotLottieReact
45-
src="https://lottie.host/fae237c0-ae74-458a-96f8-788fa3dcd895/MY7FxHtnH9.lottie"
46-
loop
47-
autoplay
48-
/>
49-
</div>
50-
);
51-
}
52-
5341
const activeCourses = myCourses.filter(course => !course.isCompleted)
5442
const completedCourses = myCourses.filter(course => course.isCompleted)
5543
const isExpert = this.props.isExpert
@@ -76,11 +64,14 @@ export default class Courses extends React.Component<Props, ICoursesState> {
7664
{completedCourses.length > 0 && <Tab label="Завершенные курсы"/>}
7765
</Tabs>
7866
{tabValue === activeCoursesTab &&
79-
<CoursesList navigate={navigate} courses={activeCourses} isExpert={isExpert}/>}
67+
<CoursesList navigate={navigate} courses={isLoaded ? activeCourses : undefined}
68+
isExpert={isExpert}/>}
8069
{tabValue === allCoursesTab && !isExpert
81-
&& <CoursesList navigate={navigate} courses={allCourses} isExpert={isExpert}/>}
70+
&&
71+
<CoursesList navigate={navigate} courses={isLoaded ? allCourses : undefined} isExpert={isExpert}/>}
8272
{tabValue === completedCoursesTab &&
83-
<CoursesList navigate={navigate} courses={completedCourses} isExpert={isExpert}/>}
73+
<CoursesList navigate={navigate} courses={isLoaded ? completedCourses : undefined}
74+
isExpert={isExpert}/>}
8475
</div>
8576
);
8677
}

hwproj.front/src/components/Courses/CoursesList.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
11
import * as React from "react";
2-
import {CoursePreviewView} from "../../api/";
2+
import {CoursePreviewView} from "@/api";
33
import {NavLink} from "react-router-dom";
44
import MentorsList from "../Common/MentorsList";
5-
import {Box, Divider, Grid, ListItem, Typography} from "@mui/material";
5+
import {Box, Divider, Grid, ListItem, Skeleton, Typography} from "@mui/material";
66
import NameBuilder from "../Utils/NameBuilder";
77

88
interface ICoursesProps {
99
navigate: any
10-
courses: CoursePreviewView[];
10+
courses: CoursePreviewView[] | undefined;
1111
isExpert: boolean
1212
}
1313

1414
export class CoursesList extends React.Component<ICoursesProps, {}> {
1515
public render() {
1616
const {courses, isExpert} = this.props;
17+
const ghostCoursesRand = [45, 12, 23, 3, 67, 50, 19]
1718

1819
return (
1920
<Box>
2021
<Grid container direction="column">
21-
{courses.map((course, i) => (
22+
{courses === undefined && ghostCoursesRand.map((rand, i) => {
23+
return <Grid item key={i}>
24+
<Skeleton variant="rectangular" animation="wave" width={300 + rand} height={25}
25+
style={{marginBottom: 5}}/>
26+
<Skeleton variant="rectangular" animation="wave" width={50 + rand} height={14}
27+
style={{marginBottom: 10}}/>
28+
<Skeleton variant="rectangular" animation="wave" width={150 + rand} height={20}/>
29+
{i < ghostCoursesRand.length - 1 ?
30+
<Divider style={{marginTop: 10, marginBottom: 10}}/> : null}
31+
</Grid>;
32+
})}
33+
{courses && courses.map((course, i) => (
2234
<Grid item key={course.id}>
2335
<ListItem
2436
style={{padding: 0, marginBottom: 5}}

0 commit comments

Comments
 (0)