From f7df4c755db7fc9ac549f2814ffeb72ead51aae4 Mon Sep 17 00:00:00 2001 From: Primakov Alexandr Date: Sun, 14 Dec 2025 15:25:53 +0300 Subject: [PATCH] Refactor TaskWorkspace to conditionally display learning materials with a button for user interaction. Update TaskPage to filter task navigation buttons based on accessibility, improving user experience in task management. --- src/components/personal/TaskWorkspace.tsx | 44 ++++++------- src/pages/task/TaskPage.tsx | 76 +++++++++++++---------- 2 files changed, 64 insertions(+), 56 deletions(-) diff --git a/src/components/personal/TaskWorkspace.tsx b/src/components/personal/TaskWorkspace.tsx index 00203e4..50fb457 100644 --- a/src/components/personal/TaskWorkspace.tsx +++ b/src/components/personal/TaskWorkspace.tsx @@ -76,7 +76,29 @@ export const TaskWorkspace = ({ task, onTaskComplete }: TaskWorkspaceProps) => { return ( + {/* Дополнительные материалы - показываются сверху */} + {task.learningMaterial && showLearningMaterial && ( + + )} + + {/* Кнопка для показа дополнительного материала */} + {task.learningMaterial && !showLearningMaterial && ( + + + + )} + {task.title} @@ -249,30 +271,8 @@ export const TaskWorkspace = ({ task, onTaskComplete }: TaskWorkspaceProps) => { > {task.description} - - {/* Кнопка для показа дополнительного материала */} - {task.learningMaterial && !showLearningMaterial && ( - - - - )} - {/* Дополнительные материалы - показываются отдельно */} - {task.learningMaterial && showLearningMaterial && ( - - )} - {/* Статус проверки и результат - фиксированное место */} diff --git a/src/pages/task/TaskPage.tsx b/src/pages/task/TaskPage.tsx index beb74c5..4482819 100644 --- a/src/pages/task/TaskPage.tsx +++ b/src/pages/task/TaskPage.tsx @@ -79,10 +79,10 @@ export const TaskPage = () => { const handleTaskComplete = () => { if (!chain || currentTaskIndex === -1) return - + const nextTaskIndex = currentTaskIndex + 1 const nextTask = chain.tasks[nextTaskIndex] - + if (nextTask) { // Обновляем прогресс перед переходом storage.setFurthestTaskIndex(chain.id, nextTaskIndex) @@ -97,15 +97,15 @@ export const TaskPage = () => { const handleNavigateToTask = (newTaskId: string) => { if (!chain) return - + const newTaskIndex = chain.tasks.findIndex(t => t.id === newTaskId) if (newTaskIndex === -1) return - + // Проверяем доступность if (!isTaskAccessible(newTaskIndex)) { return // Не переходим к заблокированному заданию } - + // Обновляем прогресс при переходе const newFurthest = Math.max(furthestTaskIndex, newTaskIndex) if (newFurthest > furthestTaskIndex) { @@ -115,6 +115,7 @@ export const TaskPage = () => { navigate(URLs.task(chain.id, newTaskId)) } + // Проверяем доступность текущего задания при загрузке useEffect(() => { if (chain && currentTaskIndex >= 0 && !isTaskAccessible(currentTaskIndex)) { @@ -138,7 +139,7 @@ export const TaskPage = () => { return null } - const taskProgress = `Задание ${currentTaskIndex + 1}` + const taskProgress = `Задание` return ( <> @@ -146,12 +147,12 @@ export const TaskPage = () => { {/* Навигация по заданиям */} - @@ -160,29 +161,36 @@ export const TaskPage = () => { Задания: - {chain.tasks.map((t, index) => { - const isAccessible = isTaskAccessible(index) - const isCurrent = t.id === taskId - - return ( - - ) - })} + {chain.tasks + .filter((_, index) => { + const isAccessible = isTaskAccessible(index) + // Показываем все доступные + только следующую недоступную + return isAccessible || index === furthestTaskIndex + 1 + }) + .map((t) => { + const taskIndex = chain.tasks.indexOf(t) + const isAccessible = isTaskAccessible(taskIndex) + const isCurrent = t.id === taskId + + return ( + + ) + })} - +