Skip to content

Commit

Permalink
fix: location (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymonMrzyglod authored Feb 15, 2024
1 parent 9e8122d commit 3627e8f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
13 changes: 5 additions & 8 deletions src/pages/TeacherSubjects/components/Exams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type { ActionType, ProColumns } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import { Button, Popconfirm, Tooltip } from 'antd';
import { format } from 'date-fns';
import type { Location } from 'history';
import React, { useMemo, useRef } from 'react';
import React, { useRef } from 'react';
import { FormattedMessage, Link, useLocation } from 'umi';

import TypeButtonDrawer from '@/components/TypeButtonDrawer';
Expand Down Expand Up @@ -76,12 +75,10 @@ const staticColumns: ProColumns<API.Exam>[] = [
export const Exams: React.FC = () => {
const actionRef = useRef<ActionType>();
const { semester_subject_id } = useTeacherSubject();
const location = useLocation() as Location & { query: { exam_id?: string; results?: string } };

const { exam_id, results } = useMemo(
() => ({ exam_id: location.query?.exam_id ?? null, results: location.query?.results }),
[location.query?.exam_id, location.query?.results],
);
const location = useLocation();
const searchParams = new URLSearchParams(location.search);
const exam_id = searchParams.get('exam_id') ?? null;
const results = searchParams.get('results');

if (results !== null && !Number.isNaN(Number(results))) {
return <ExamResults exam_id={Number(results)} />;
Expand Down
20 changes: 5 additions & 15 deletions src/pages/TeacherSubjects/components/FinalGradesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { EditOutlined } from '@ant-design/icons';
import type { ProColumns } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import { Button, Tooltip, Typography } from 'antd';
import type { Location } from 'history';
import React, { useMemo } from 'react';
import { FormattedMessage, Link, useLocation } from 'umi';

Expand Down Expand Up @@ -48,19 +47,10 @@ const staticColumns: ProColumns<API.FinalGradeItem>[] = [
];

export const FinalGradesList: React.FC = () => {
const location = useLocation() as Location & { query: { user_id?: string; group_id?: string } };
const { user_id, group_id } = useMemo(
() => ({
user_id: Number.isNaN(Number(location.query?.user_id))
? null
: Number(location.query?.user_id),
group_id: Number.isNaN(Number(location.query?.group_id))
? null
: Number(location.query?.group_id),
}),

[location.query?.user_id, location.query?.group_id],
);
const location = useLocation();
const searchParams = new URLSearchParams(location.search);
const user_id = searchParams.get('user_id') ?? null;
const group_id = searchParams.get('group_id') ?? null;

const { teacherSubjectData, semester_subject_id } = useTeacherSubject();

Expand All @@ -70,7 +60,7 @@ export const FinalGradesList: React.FC = () => {
);

if (user_id !== null && group_id !== null) {
return <FinalGradesDetails user_id={user_id} group_id={group_id} />;
return <FinalGradesDetails user_id={Number(user_id)} group_id={Number(group_id)} />;
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/services/escola-lms/grades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function getGroupFinalGrades(
) {
return request<API.DefaultResponse<API.FinalGradeItem[]>>(`/api/admin/lesson-group-users`, {
method: 'GET',
params: { 'groups[]': group_id },
params: { groups: group_id },
/* useCache: true */ useCache: false,
...(options || {}),
});
Expand Down

0 comments on commit 3627e8f

Please sign in to comment.