diff --git a/src/pages/CourseExercises.tsx b/src/pages/CourseExercises.tsx index 177b3a1..ff50f12 100644 --- a/src/pages/CourseExercises.tsx +++ b/src/pages/CourseExercises.tsx @@ -1,7 +1,7 @@ "use client" import { useState, useEffect } from "react"; -import { useParams, useHistory } from "react-router-dom"; +import { useParams, useHistory, useLocation } from "react-router-dom"; import HeaderNav from "../components/HeaderNav"; import BottomNavigation from "../components/BottomNavigation"; @@ -11,8 +11,9 @@ import { connect } from '../confconnect'; import { getRouteExercise } from "../shared/consts/router"; import { ArrowIcon } from "../components/icons/ArrowIcon"; +import type { Course } from "../pages/Courses"; -interface CourseExercises { +export interface CourseExercises { id_course: number; id_exercise: number; exercise: Exercise; @@ -25,8 +26,6 @@ interface CourseExercises { interface Exercise { id: number; title: string; - - } @@ -34,6 +33,11 @@ export const CourseExercises = () => { const history = useHistory(); const { id } = useParams<{ id: string }>(); + + const location = useLocation<{ course?: Course }>(); + const course = location.state?.course; + + // const [pacientData, setPacientData] = useState(null); const [course_exercises, setExercises] = useState([]); @@ -41,6 +45,8 @@ export const CourseExercises = () => { const token = localStorage.getItem('authToken'); + + useEffect(() => { console.log(token) if (!token) { @@ -99,7 +105,9 @@ export const CourseExercises = () => {
- + +{/* Это выражение использует оператор опциональной цепочки (?.) и оператор нулевого слияния (??). +Если course не null и не undefined, то взять его свойство title, иначе — вернуть undefined*/}
@@ -162,7 +170,7 @@ export const CourseExercises = () => {

Повторений: {item.repeats}

- +

Время выполнения: {item.time}

diff --git a/src/pages/Courses.tsx b/src/pages/Courses.tsx index 7100851..387c9ce 100644 --- a/src/pages/Courses.tsx +++ b/src/pages/Courses.tsx @@ -16,6 +16,8 @@ export interface Course { url_file_img: string; } + + const ProgressLine = () => { return (
{ Authorization: `Bearer ${token}`, }, }) - .then(response => { - console.log('Response status:', response.status); - - // Предполагаемая структура: - // response.data.courses — массив пользователей - const users = response.data.courses || []; + .then(response => { + console.log('Response status:', response.status); - // Собираем все курсы из всех пользователей - const allCourses: Course[] = []; + // Предполагаемая структура: + // response.data.courses — массив пользователей + const users = response.data.courses || []; - users.forEach(user => { - if (user.Courses && Array.isArray(user.Courses)) { - user.Courses.forEach(course => { - // Можно добавить проверку или преобразование - allCourses.push({ - ID: course.id, // или course.ID, зависит от структуры - title: course.title, - desc: course.desc, - url_file_img: course.url_file_img, + // Собираем все курсы из всех пользователей + const allCourses: Course[] = []; + + users.forEach(user => { + if (user.Courses && Array.isArray(user.Courses)) { + user.Courses.forEach(course => { + // Можно добавить проверку или преобразование + allCourses.push({ + ID: course.id, // или course.ID, зависит от структуры + title: course.title, + desc: course.desc, + url_file_img: course.url_file_img, + }); }); - }); + } + }); + + + setCourses(allCourses); + }) + .catch(error => { + if (error.response) { + console.error('Ошибка ответа сервера:', error.response.status, error.response.data); + setError(`Ошибка сервера: ${error.response.status}`); + } else if (error.request) { + console.error('Нет ответа от сервера:', error.request); + setError('Нет ответа от сервера'); + } else { + console.error('Ошибка при настройке запроса:', error.message); + setError(`Ошибка: ${error.message}`); } }); - - setCourses(allCourses); - }) - .catch(error => { - if (error.response) { - console.error('Ошибка ответа сервера:', error.response.status, error.response.data); - setError(`Ошибка сервера: ${error.response.status}`); - } else if (error.request) { - console.error('Нет ответа от сервера:', error.request); - setError('Нет ответа от сервера'); - } else { - console.error('Ошибка при настройке запроса:', error.message); - setError(`Ошибка: ${error.message}`); - } - }); }, [token]); - // Генерируем случайный прогресс для каждого курса const getRandomProgress = () => Math.floor(Math.random() * 100); @@ -115,7 +117,7 @@ export const Courses = () => { "from-gray-400 to-cyan-800", ]; -//item.exercise.title + //item.exercise.title return ( @@ -142,20 +144,20 @@ export const Courses = () => { courses.map((course, index) => { const progress = getRandomProgress(); const colorClass = progressColors[index % progressColors.length]; - + return ( -
history.push(getRouteCourseExercises(course.ID.toString()))} +
history.push(getRouteCourseExercises(course.ID.toString()), { course })} className="bg-white/30 backdrop-blur-2xl rounded-3xl p-6 border border-white/20 shadow-xl cursor-pointer hover:shadow-2xl transition-all duration-300 transform hover:scale-[1.02]" >
{/* Изображение курса */} {course.url_file_img && (
- {course.title} { e.currentTarget.src = "/placeholder.svg?height=64&width=64&text=Course" @@ -166,7 +168,7 @@ export const Courses = () => {

{course.title}

- + {/* Описание курса */} {course.desc && (

{course.desc}

@@ -201,7 +203,7 @@ export const Courses = () => { !error && (

У вас пока нет назначенных курсов

-