тестовый вывод дней по порядку, исключая удаленные
This commit is contained in:
parent
32625b9034
commit
d47fe0d338
6
src/components/icons/test.tsx
Normal file
6
src/components/icons/test.tsx
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
const allExercises = course_exercises;
|
||||||
|
const uniqueDays = Array.from(new Set(allExercises.map(ex => ex.day))).sort((a, b) => a - b);
|
||||||
|
const dayMap: { [key: number]: number } = {};
|
||||||
|
uniqueDays.forEach((day, index) => {
|
||||||
|
dayMap[day] = index + 1; // номера начинаются с 1
|
||||||
|
});
|
@ -1,5 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useParams, useHistory, useLocation } from "react-router-dom";
|
import { useParams, useHistory, useLocation } from "react-router-dom";
|
||||||
|
|
||||||
@ -12,6 +14,7 @@ import { getRouteExercise } from "../shared/consts/router";
|
|||||||
import { ArrowIcon } from "../components/icons/ArrowIcon";
|
import { ArrowIcon } from "../components/icons/ArrowIcon";
|
||||||
|
|
||||||
import type { Course } from "../pages/Courses";
|
import type { Course } from "../pages/Courses";
|
||||||
|
// import { Exercise } from "./Exercise";
|
||||||
|
|
||||||
export interface CourseExercises {
|
export interface CourseExercises {
|
||||||
id_course: number;
|
id_course: number;
|
||||||
@ -21,6 +24,7 @@ export interface CourseExercises {
|
|||||||
position: number;
|
position: number;
|
||||||
repeats: number;
|
repeats: number;
|
||||||
time: string;
|
time: string;
|
||||||
|
DeletedAt: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Exercise {
|
interface Exercise {
|
||||||
@ -64,7 +68,7 @@ export const CourseExercises = () => {
|
|||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
console.log('Response status:', response.status);
|
console.log('Response status:', response.status);
|
||||||
console.log('Данные:', response.data);
|
console.log('Данные страницы упражнения курса:', response.data);
|
||||||
// setPacientData(response.data);
|
// setPacientData(response.data);
|
||||||
setExercises(response.data.course_exercises);
|
setExercises(response.data.course_exercises);
|
||||||
|
|
||||||
@ -92,31 +96,49 @@ export const CourseExercises = () => {
|
|||||||
}, [course_exercises]);
|
}, [course_exercises]);
|
||||||
|
|
||||||
|
|
||||||
const days = Array.from(new Set(course_exercises.map(ex => ex.day))).sort((a, b) => a - b);
|
|
||||||
|
|
||||||
const filteredExercises = selectedDay !== null
|
const filteredExercises = selectedDay !== null
|
||||||
? course_exercises.filter(ex => ex.day === selectedDay)
|
? course_exercises.filter(ex => ex.day === selectedDay)
|
||||||
: course_exercises;
|
: course_exercises;
|
||||||
|
|
||||||
|
|
||||||
|
const allExercises = course_exercises;
|
||||||
|
const uniqueDays = Array.from(new Set(allExercises.map(ex => ex.day))).sort((a, b) => a - b);
|
||||||
|
const dayMap: { [key: number]: number } = {};
|
||||||
|
uniqueDays.forEach((day, index) => {
|
||||||
|
dayMap[day] = index + 1; // номера начинаются с 1
|
||||||
|
});
|
||||||
|
|
||||||
|
const daysNav = uniqueDays.map(day => dayMap[day]);
|
||||||
|
|
||||||
|
const days = Array.from(new Set(course_exercises.map(ex => ex.day))).sort((a, b) => a - b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//тут выводим дни из БД
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
|
|
||||||
<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={course?.title ?? 'Название курса'} text={'курс'} />
|
<HeaderNav item={course?.title ?? 'Название курса'} text={'курс'} />
|
||||||
{/* Это выражение использует оператор опциональной цепочки (?.) и оператор нулевого слияния (??).
|
{/* Это выражение использует оператор опциональной цепочки (?.) и оператор нулевого слияния (??).
|
||||||
Если course не null и не undefined, то взять его свойство title, иначе — вернуть undefined*/}
|
Если course не null и не undefined, то взять его свойство title, иначе — вернуть undefined*/}
|
||||||
|
|
||||||
<div className="px-6 mb-8">
|
<div className="px-6 mb-8">
|
||||||
|
|
||||||
{/* Заголовок секции */}
|
{/* Заголовок секции */}
|
||||||
<div className="flex items-center justify-between mb-6">
|
<div className="flex flex-col sm:flex-row items-center justify-between mb-6">
|
||||||
<h2 className="text-xl font-black text-[#5F5C5C]">Упражнения</h2>
|
<h2 className="text-xl font-black text-[#5F5C5C]">Упражнения</h2>
|
||||||
<span className="text-sm text-gray-500">Количество упражнений: {course_exercises.length}</span>
|
<span className="text-sm text-gray-500">Количество упражнений: {course_exercises.length}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<p>{uniqueDays}</p>
|
||||||
|
|
||||||
|
|
||||||
|
{/* <p>{JSON.stringify(course_exercises)}</p> */}
|
||||||
|
|
||||||
|
|
||||||
|
{daysNav}
|
||||||
{/* Кнопки выбора дня */}
|
{/* Кнопки выбора дня */}
|
||||||
{days.length > 1 && (
|
{days.length > 1 && (
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user