поправила вывод курса в шапку
This commit is contained in:
parent
a1d945b854
commit
17ee7354dc
@ -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<CourseExercises[]>([]);
|
||||
@ -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 = () => {
|
||||
|
||||
<div className="my-36 min-h-screen max-w-4xl mx-auto">
|
||||
|
||||
<HeaderNav item={'Курс' + ' ' + id} text={'список упражнений'} />
|
||||
<HeaderNav item={course?.title ?? 'Название курса'} text={'курс'} />
|
||||
{/* Это выражение использует оператор опциональной цепочки (?.) и оператор нулевого слияния (??).
|
||||
Если course не null и не undefined, то взять его свойство title, иначе — вернуть undefined*/}
|
||||
|
||||
<div className="px-6 mb-8">
|
||||
|
||||
@ -162,7 +170,7 @@ export const CourseExercises = () => {
|
||||
|
||||
<div className="flex gap-10 text-xs text-gray-500">
|
||||
<p>Повторений: {item.repeats}</p>
|
||||
|
||||
|
||||
<p>Время выполнения: {item.time}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -16,6 +16,8 @@ export interface Course {
|
||||
url_file_img: string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const ProgressLine = () => {
|
||||
return (
|
||||
<div
|
||||
@ -64,49 +66,49 @@ export const Courses = () => {
|
||||
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 (
|
||||
<div
|
||||
key={course.ID}
|
||||
onClick={() => history.push(getRouteCourseExercises(course.ID.toString()))}
|
||||
<div
|
||||
key={course.ID}
|
||||
onClick={() => 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]"
|
||||
>
|
||||
<div className="flex items-center space-x-5">
|
||||
{/* Изображение курса */}
|
||||
{course.url_file_img && (
|
||||
<div className="w-16 h-16 rounded-2xl overflow-hidden flex-shrink-0">
|
||||
<img
|
||||
src={course.url_file_img || "/placeholder.svg"}
|
||||
alt={course.title}
|
||||
<img
|
||||
src={course.url_file_img || "/placeholder.svg"}
|
||||
alt={course.title}
|
||||
className="w-full h-full object-cover"
|
||||
onError={(e) => {
|
||||
e.currentTarget.src = "/placeholder.svg?height=64&width=64&text=Course"
|
||||
@ -166,7 +168,7 @@ export const Courses = () => {
|
||||
|
||||
<div className="flex-1">
|
||||
<h3 className="font-semibold text-[#5F5C5C] text-lg mb-2">{course.title}</h3>
|
||||
|
||||
|
||||
{/* Описание курса */}
|
||||
{course.desc && (
|
||||
<p className="text-sm text-[#5F5C5C]/60 mb-3 line-clamp-2">{course.desc}</p>
|
||||
@ -201,7 +203,7 @@ export const Courses = () => {
|
||||
!error && (
|
||||
<div className="bg-gray-50 border border-gray-200 rounded-lg p-8 text-center">
|
||||
<p className="text-gray-600 mb-4">У вас пока нет назначенных курсов</p>
|
||||
<button
|
||||
<button
|
||||
onClick={() => history.push("/courses")}
|
||||
className="bg-[#2BACBE] text-white px-4 py-2 rounded-lg hover:bg-[#2A9FB8] transition-colors"
|
||||
>
|
||||
|
@ -389,7 +389,7 @@ export const Exercise = () => {
|
||||
onTouchStart={() => setIsActive(true)}
|
||||
onTouchEnd={() => setIsActive(false)}
|
||||
|
||||
className={`cursor-pointer px-6 py-3 font-bold rounded-xl transition-all duration-700 hover:scale-105 hover:shadow-lg border border-gray-200 flex items-center justify-center ${!isActive ? "bg-white text-cyan-500" : "bg-orange-400 text-white"}`}
|
||||
className={`cursor-pointer px-6 py-3 font-bold rounded-xl transition-all duration-700 hover:scale-105 hover:shadow-lg border border-gray-200 flex items-center justify-center ${!isActive ? "bg-white text-orange-400" : "bg-orange-400 text-white"}`}
|
||||
>
|
||||
<CheckIcon
|
||||
className="w-6 h-6"
|
||||
|
Loading…
x
Reference in New Issue
Block a user