поправила вывод курса в шапку
This commit is contained in:
parent
a1d945b854
commit
17ee7354dc
@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useState, useEffect } from "react";
|
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 HeaderNav from "../components/HeaderNav";
|
||||||
import BottomNavigation from "../components/BottomNavigation";
|
import BottomNavigation from "../components/BottomNavigation";
|
||||||
@ -11,8 +11,9 @@ import { connect } from '../confconnect';
|
|||||||
import { getRouteExercise } from "../shared/consts/router";
|
import { getRouteExercise } from "../shared/consts/router";
|
||||||
import { ArrowIcon } from "../components/icons/ArrowIcon";
|
import { ArrowIcon } from "../components/icons/ArrowIcon";
|
||||||
|
|
||||||
|
import type { Course } from "../pages/Courses";
|
||||||
|
|
||||||
interface CourseExercises {
|
export interface CourseExercises {
|
||||||
id_course: number;
|
id_course: number;
|
||||||
id_exercise: number;
|
id_exercise: number;
|
||||||
exercise: Exercise;
|
exercise: Exercise;
|
||||||
@ -25,8 +26,6 @@ interface CourseExercises {
|
|||||||
interface Exercise {
|
interface Exercise {
|
||||||
id: number;
|
id: number;
|
||||||
title: string;
|
title: string;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -34,6 +33,11 @@ export const CourseExercises = () => {
|
|||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { id } = useParams<{ id: string }>();
|
const { id } = useParams<{ id: string }>();
|
||||||
|
|
||||||
|
|
||||||
|
const location = useLocation<{ course?: Course }>();
|
||||||
|
const course = location.state?.course;
|
||||||
|
|
||||||
|
|
||||||
// const [pacientData, setPacientData] = useState(null);
|
// const [pacientData, setPacientData] = useState(null);
|
||||||
|
|
||||||
const [course_exercises, setExercises] = useState<CourseExercises[]>([]);
|
const [course_exercises, setExercises] = useState<CourseExercises[]>([]);
|
||||||
@ -41,6 +45,8 @@ export const CourseExercises = () => {
|
|||||||
|
|
||||||
const token = localStorage.getItem('authToken');
|
const token = localStorage.getItem('authToken');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(token)
|
console.log(token)
|
||||||
if (!token) {
|
if (!token) {
|
||||||
@ -99,7 +105,9 @@ export const CourseExercises = () => {
|
|||||||
|
|
||||||
<div className="my-36 min-h-screen max-w-4xl mx-auto">
|
<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">
|
<div className="px-6 mb-8">
|
||||||
|
|
||||||
@ -162,7 +170,7 @@ export const CourseExercises = () => {
|
|||||||
|
|
||||||
<div className="flex gap-10 text-xs text-gray-500">
|
<div className="flex gap-10 text-xs text-gray-500">
|
||||||
<p>Повторений: {item.repeats}</p>
|
<p>Повторений: {item.repeats}</p>
|
||||||
|
|
||||||
<p>Время выполнения: {item.time}</p>
|
<p>Время выполнения: {item.time}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -16,6 +16,8 @@ export interface Course {
|
|||||||
url_file_img: string;
|
url_file_img: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const ProgressLine = () => {
|
const ProgressLine = () => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -64,49 +66,49 @@ export const Courses = () => {
|
|||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
console.log('Response status:', response.status);
|
console.log('Response status:', response.status);
|
||||||
|
|
||||||
// Предполагаемая структура:
|
|
||||||
// response.data.courses — массив пользователей
|
|
||||||
const users = response.data.courses || [];
|
|
||||||
|
|
||||||
// Собираем все курсы из всех пользователей
|
// Предполагаемая структура:
|
||||||
const allCourses: Course[] = [];
|
// response.data.courses — массив пользователей
|
||||||
|
const users = response.data.courses || [];
|
||||||
|
|
||||||
users.forEach(user => {
|
// Собираем все курсы из всех пользователей
|
||||||
if (user.Courses && Array.isArray(user.Courses)) {
|
const allCourses: Course[] = [];
|
||||||
user.Courses.forEach(course => {
|
|
||||||
// Можно добавить проверку или преобразование
|
users.forEach(user => {
|
||||||
allCourses.push({
|
if (user.Courses && Array.isArray(user.Courses)) {
|
||||||
ID: course.id, // или course.ID, зависит от структуры
|
user.Courses.forEach(course => {
|
||||||
title: course.title,
|
// Можно добавить проверку или преобразование
|
||||||
desc: course.desc,
|
allCourses.push({
|
||||||
url_file_img: course.url_file_img,
|
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]);
|
}, [token]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Генерируем случайный прогресс для каждого курса
|
// Генерируем случайный прогресс для каждого курса
|
||||||
const getRandomProgress = () => Math.floor(Math.random() * 100);
|
const getRandomProgress = () => Math.floor(Math.random() * 100);
|
||||||
|
|
||||||
@ -115,7 +117,7 @@ export const Courses = () => {
|
|||||||
"from-gray-400 to-cyan-800",
|
"from-gray-400 to-cyan-800",
|
||||||
];
|
];
|
||||||
|
|
||||||
//item.exercise.title
|
//item.exercise.title
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -142,20 +144,20 @@ export const Courses = () => {
|
|||||||
courses.map((course, index) => {
|
courses.map((course, index) => {
|
||||||
const progress = getRandomProgress();
|
const progress = getRandomProgress();
|
||||||
const colorClass = progressColors[index % progressColors.length];
|
const colorClass = progressColors[index % progressColors.length];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={course.ID}
|
key={course.ID}
|
||||||
onClick={() => history.push(getRouteCourseExercises(course.ID.toString()))}
|
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]"
|
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">
|
<div className="flex items-center space-x-5">
|
||||||
{/* Изображение курса */}
|
{/* Изображение курса */}
|
||||||
{course.url_file_img && (
|
{course.url_file_img && (
|
||||||
<div className="w-16 h-16 rounded-2xl overflow-hidden flex-shrink-0">
|
<div className="w-16 h-16 rounded-2xl overflow-hidden flex-shrink-0">
|
||||||
<img
|
<img
|
||||||
src={course.url_file_img || "/placeholder.svg"}
|
src={course.url_file_img || "/placeholder.svg"}
|
||||||
alt={course.title}
|
alt={course.title}
|
||||||
className="w-full h-full object-cover"
|
className="w-full h-full object-cover"
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
e.currentTarget.src = "/placeholder.svg?height=64&width=64&text=Course"
|
e.currentTarget.src = "/placeholder.svg?height=64&width=64&text=Course"
|
||||||
@ -166,7 +168,7 @@ export const Courses = () => {
|
|||||||
|
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<h3 className="font-semibold text-[#5F5C5C] text-lg mb-2">{course.title}</h3>
|
<h3 className="font-semibold text-[#5F5C5C] text-lg mb-2">{course.title}</h3>
|
||||||
|
|
||||||
{/* Описание курса */}
|
{/* Описание курса */}
|
||||||
{course.desc && (
|
{course.desc && (
|
||||||
<p className="text-sm text-[#5F5C5C]/60 mb-3 line-clamp-2">{course.desc}</p>
|
<p className="text-sm text-[#5F5C5C]/60 mb-3 line-clamp-2">{course.desc}</p>
|
||||||
@ -201,7 +203,7 @@ export const Courses = () => {
|
|||||||
!error && (
|
!error && (
|
||||||
<div className="bg-gray-50 border border-gray-200 rounded-lg p-8 text-center">
|
<div className="bg-gray-50 border border-gray-200 rounded-lg p-8 text-center">
|
||||||
<p className="text-gray-600 mb-4">У вас пока нет назначенных курсов</p>
|
<p className="text-gray-600 mb-4">У вас пока нет назначенных курсов</p>
|
||||||
<button
|
<button
|
||||||
onClick={() => history.push("/courses")}
|
onClick={() => history.push("/courses")}
|
||||||
className="bg-[#2BACBE] text-white px-4 py-2 rounded-lg hover:bg-[#2A9FB8] transition-colors"
|
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)}
|
onTouchStart={() => setIsActive(true)}
|
||||||
onTouchEnd={() => setIsActive(false)}
|
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
|
<CheckIcon
|
||||||
className="w-6 h-6"
|
className="w-6 h-6"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user