Skip to content

Commit f13bceb

Browse files
committed
refactor
1 parent accbd66 commit f13bceb

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from "react";
22
import {Link as RouterLink} from "react-router-dom";
3-
import {RouteComponentProps} from 'react-router';
43
import {AccountDataDto, CourseViewModel, HomeworkViewModel, StatisticsCourseMatesModel} from "../../api";
54
import CourseHomework from "../Homeworks/CourseHomework";
65
import AddHomework from "../Homeworks/AddHomework";
@@ -40,18 +39,14 @@ interface IPageState {
4039
tabValue: TabValue
4140
}
4241

43-
interface ICourseProps {
44-
id: string;
45-
}
46-
4742
const styles = makeStyles(() => ({
4843
info: {
4944
display: "flex",
5045
justifyContent: "space-between",
5146
},
5247
}))
5348

54-
const Course: React.FC<RouteComponentProps<ICourseProps>> = (props) => {
49+
const Course: React.FC = () => {
5550
const getLastViewedCourseId = () =>
5651
{
5752
const sessionStorageCourseId = sessionStorage.getItem("courseId")
@@ -63,10 +58,9 @@ const Course: React.FC<RouteComponentProps<ICourseProps>> = (props) => {
6358
sessionStorage.setItem("courseId", courseId)
6459
}
6560

66-
const courseIdFromProps = props.match.params.id
67-
const isFromYandex = courseIdFromProps === undefined
68-
const courseId = isFromYandex ? getLastViewedCourseId() : courseIdFromProps
69-
const {tab} = useParams()
61+
let {courseId, tab} = useParams()
62+
const isFromYandex = courseId === undefined
63+
courseId = isFromYandex ? getLastViewedCourseId() : courseId
7064
const navigate = useNavigate()
7165
const classes = styles()
7266

@@ -132,7 +126,7 @@ const Course: React.FC<RouteComponentProps<ICourseProps>> = (props) => {
132126
}
133127

134128
const setCurrentState = async () => {
135-
updatedLastViewedCourseId(courseId)
129+
updatedLastViewedCourseId(courseId!)
136130
const course = await ApiSingleton.coursesApi.apiCoursesByCourseIdGet(+courseId!)
137131
const solutions = await ApiSingleton.statisticsApi.apiStatisticsByCourseIdGet(+courseId!)
138132

@@ -162,11 +156,11 @@ const Course: React.FC<RouteComponentProps<ICourseProps>> = (props) => {
162156

163157
const getUserYandexCode = (url: string) =>
164158
{
165-
const queryParameters = new URLSearchParams(window.location.search)
159+
const queryParameters = new URLSearchParams(url)
166160
return queryParameters.get("code")
167161
}
168162

169-
const id = getUserYandexCode(props.location.search)
163+
const yandexCode = getUserYandexCode(window.location.search)
170164

171165
const joinCourse = async () => {
172166
await ApiSingleton.coursesApi
@@ -361,7 +355,7 @@ const Course: React.FC<RouteComponentProps<ICourseProps>> = (props) => {
361355
isMentor={isMentor}
362356
course={courseState.course}
363357
solutions={studentSolutions}
364-
yandexCode={id}
358+
yandexCode={yandexCode}
365359
/>
366360
</Grid>
367361
</Grid>}

0 commit comments

Comments
 (0)