feat(teacher): режим flip-карточек для уроков (22.09.2026)
This commit is contained in:
@@ -0,0 +1,480 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { radius } from '../styles/theme';
|
||||||
|
|
||||||
|
// ============ Типы ============
|
||||||
|
|
||||||
|
export type CardType = 'intro' | 'question' | 'result' | 'test_summary';
|
||||||
|
|
||||||
|
export interface LessonCardOption {
|
||||||
|
option_key: string;
|
||||||
|
text_pl: string;
|
||||||
|
text_ru: string;
|
||||||
|
text_uk: string;
|
||||||
|
text_en: string;
|
||||||
|
is_correct: boolean;
|
||||||
|
wrong_because?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LessonCardData {
|
||||||
|
type: CardType;
|
||||||
|
|
||||||
|
// Для intro
|
||||||
|
levelCode?: string;
|
||||||
|
topicName?: string;
|
||||||
|
lessonNumber?: number;
|
||||||
|
lessonTitle?: string;
|
||||||
|
explanation?: string;
|
||||||
|
examples?: Array<{ text_pl: string; text_user: string }>;
|
||||||
|
|
||||||
|
// Для question
|
||||||
|
questionId?: string;
|
||||||
|
questionType?: 'recognition' | 'production';
|
||||||
|
prompt?: string;
|
||||||
|
options?: LessonCardOption[];
|
||||||
|
optionsLanguage?: 'pl' | 'user';
|
||||||
|
|
||||||
|
// Для result / test_summary
|
||||||
|
resultText?: string;
|
||||||
|
correctCount?: number;
|
||||||
|
totalCount?: number;
|
||||||
|
weakSkill?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LessonCardProps {
|
||||||
|
data: LessonCardData;
|
||||||
|
cardIndex: number;
|
||||||
|
totalCards: number;
|
||||||
|
selectedAnswer: string | null;
|
||||||
|
textInput: string;
|
||||||
|
hintUsed: boolean;
|
||||||
|
isFlipping: boolean;
|
||||||
|
rotation: number;
|
||||||
|
|
||||||
|
onSelectAnswer: (optionKey: string) => void;
|
||||||
|
onTextChange: (text: string) => void;
|
||||||
|
onNext: () => void;
|
||||||
|
onShowHint: () => void;
|
||||||
|
onStartLesson?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const LessonCard: React.FC<LessonCardProps> = ({
|
||||||
|
data,
|
||||||
|
cardIndex,
|
||||||
|
totalCards,
|
||||||
|
selectedAnswer,
|
||||||
|
textInput,
|
||||||
|
hintUsed,
|
||||||
|
isFlipping,
|
||||||
|
rotation,
|
||||||
|
onSelectAnswer,
|
||||||
|
onTextChange,
|
||||||
|
onNext,
|
||||||
|
onShowHint,
|
||||||
|
onStartLesson,
|
||||||
|
}) => {
|
||||||
|
const textColor = '#1A1A2E';
|
||||||
|
const subColor = '#6B7280';
|
||||||
|
const brandColor = '#2ECC71';
|
||||||
|
const teacherColor = '#8B5CF6';
|
||||||
|
|
||||||
|
const glass = (extra: React.CSSProperties = {}): React.CSSProperties => ({
|
||||||
|
background: 'rgba(255,255,255,0.55)',
|
||||||
|
backdropFilter: 'blur(24px) saturate(180%)',
|
||||||
|
WebkitBackdropFilter: 'blur(24px) saturate(180%)',
|
||||||
|
border: '1px solid rgba(255,255,255,0.7)',
|
||||||
|
boxShadow: '0 8px 32px rgba(31,38,73,0.10), inset 0 1px 0 rgba(255,255,255,0.85)',
|
||||||
|
...extra,
|
||||||
|
});
|
||||||
|
|
||||||
|
const progressPercent = totalCards > 0 ? ((cardIndex + 1) / totalCards) * 100 : 0;
|
||||||
|
|
||||||
|
// ============ Титульная ============
|
||||||
|
const renderIntro = () => (
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '16px', height: '100%' }}>
|
||||||
|
<div style={{ textAlign: 'center' }}>
|
||||||
|
<div style={{
|
||||||
|
fontSize: '14px',
|
||||||
|
fontWeight: 700,
|
||||||
|
color: teacherColor,
|
||||||
|
marginBottom: '4px',
|
||||||
|
letterSpacing: '0.5px',
|
||||||
|
textTransform: 'uppercase',
|
||||||
|
}}>
|
||||||
|
{data.levelCode} · {data.topicName}
|
||||||
|
</div>
|
||||||
|
<div style={{ fontSize: '12px', color: subColor, marginBottom: '8px' }}>
|
||||||
|
Урок {data.lessonNumber}
|
||||||
|
</div>
|
||||||
|
<h2 style={{
|
||||||
|
fontSize: '22px',
|
||||||
|
fontWeight: 900,
|
||||||
|
color: textColor,
|
||||||
|
margin: 0,
|
||||||
|
lineHeight: '1.3',
|
||||||
|
}}>
|
||||||
|
{data.lessonTitle}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{data.explanation && (
|
||||||
|
<div style={{
|
||||||
|
padding: '14px',
|
||||||
|
background: `${brandColor}10`,
|
||||||
|
borderRadius: radius.md,
|
||||||
|
fontSize: '14px',
|
||||||
|
color: textColor,
|
||||||
|
lineHeight: '1.6',
|
||||||
|
whiteSpace: 'pre-line',
|
||||||
|
}}>
|
||||||
|
{data.explanation}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{data.examples && data.examples.length > 0 && (
|
||||||
|
<div style={{
|
||||||
|
padding: '12px',
|
||||||
|
background: `${teacherColor}08`,
|
||||||
|
borderRadius: radius.md,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '8px',
|
||||||
|
}}>
|
||||||
|
<div style={{ fontSize: '11px', fontWeight: 700, color: teacherColor, textTransform: 'uppercase', letterSpacing: '0.5px' }}>
|
||||||
|
Przykłady
|
||||||
|
</div>
|
||||||
|
{data.examples.map((ex, i) => (
|
||||||
|
<div key={i} style={{ fontSize: '13px', lineHeight: '1.5' }}>
|
||||||
|
<span style={{ fontWeight: 700, color: textColor }}>🇵🇱 {ex.text_pl}</span>
|
||||||
|
{ex.text_user && (
|
||||||
|
<span style={{ color: subColor }}> → {ex.text_user}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div style={{ flex: 1 }} />
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={onStartLesson}
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
padding: '16px',
|
||||||
|
borderRadius: radius.lg,
|
||||||
|
border: 'none',
|
||||||
|
background: `linear-gradient(135deg, ${teacherColor}, #6B46C1)`,
|
||||||
|
color: '#FFFFFF',
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: 800,
|
||||||
|
cursor: 'pointer',
|
||||||
|
boxShadow: `0 4px 15px ${teacherColor}40`,
|
||||||
|
transition: 'all 0.2s ease',
|
||||||
|
}}
|
||||||
|
onTouchStart={(e) => { e.currentTarget.style.transform = 'scale(0.96)'; }}
|
||||||
|
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
|
||||||
|
>
|
||||||
|
Перейти к заданию →
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
// ============ Вопрос ============
|
||||||
|
const renderQuestion = () => {
|
||||||
|
const isProduction = data.questionType === 'production';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '16px', height: '100%' }}>
|
||||||
|
{!hintUsed && (
|
||||||
|
<button
|
||||||
|
onClick={onShowHint}
|
||||||
|
title="Подсказка"
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: '16px',
|
||||||
|
right: '16px',
|
||||||
|
width: '36px',
|
||||||
|
height: '36px',
|
||||||
|
borderRadius: '50%',
|
||||||
|
border: `1px solid ${brandColor}40`,
|
||||||
|
background: `${brandColor}15`,
|
||||||
|
color: brandColor,
|
||||||
|
fontSize: '18px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
padding: 0,
|
||||||
|
boxShadow: '0 2px 8px rgba(31,38,73,0.10)',
|
||||||
|
transition: 'all 0.2s ease',
|
||||||
|
zIndex: 2,
|
||||||
|
}}
|
||||||
|
onTouchStart={(e) => { e.currentTarget.style.transform = 'scale(0.9)'; }}
|
||||||
|
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
|
||||||
|
>
|
||||||
|
💡
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{hintUsed && (
|
||||||
|
<div style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: '16px',
|
||||||
|
right: '16px',
|
||||||
|
fontSize: '11px',
|
||||||
|
color: subColor,
|
||||||
|
fontWeight: 700,
|
||||||
|
padding: '4px 10px',
|
||||||
|
background: 'rgba(0,0,0,0.05)',
|
||||||
|
borderRadius: radius.sm,
|
||||||
|
zIndex: 2,
|
||||||
|
}}>
|
||||||
|
🔒 подсказка
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div style={{ paddingRight: '48px' }}>
|
||||||
|
<div style={{ fontSize: '11px', fontWeight: 700, color: subColor, marginBottom: '6px', textTransform: 'uppercase', letterSpacing: '0.5px' }}>
|
||||||
|
Задание {cardIndex}
|
||||||
|
</div>
|
||||||
|
<div style={{ fontSize: '17px', fontWeight: 700, color: textColor, lineHeight: '1.4' }}>
|
||||||
|
{data.prompt}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{isProduction ? (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={textInput}
|
||||||
|
onChange={(e) => onTextChange(e.target.value)}
|
||||||
|
placeholder="Введите ответ..."
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
padding: '14px',
|
||||||
|
borderRadius: radius.md,
|
||||||
|
border: textInput ? `2px solid ${brandColor}` : '1px solid rgba(0,0,0,0.08)',
|
||||||
|
background: 'rgba(255,255,255,0.9)',
|
||||||
|
color: textColor,
|
||||||
|
fontSize: '16px',
|
||||||
|
fontWeight: 600,
|
||||||
|
outline: 'none',
|
||||||
|
boxSizing: 'border-box',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
|
||||||
|
{(data.options || []).map((opt) => {
|
||||||
|
const isSelected = selectedAnswer === opt.option_key;
|
||||||
|
const displayText = data.optionsLanguage === 'user'
|
||||||
|
? (opt.text_ru || opt.text_en || opt.text_pl)
|
||||||
|
: opt.text_pl;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={opt.option_key}
|
||||||
|
onClick={() => onSelectAnswer(opt.option_key)}
|
||||||
|
style={{
|
||||||
|
padding: '14px 16px',
|
||||||
|
borderRadius: radius.md,
|
||||||
|
border: isSelected ? `2px solid ${brandColor}` : '1px solid rgba(0,0,0,0.08)',
|
||||||
|
background: isSelected ? `${brandColor}15` : 'rgba(255,255,255,0.7)',
|
||||||
|
color: textColor,
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: isSelected ? 700 : 500,
|
||||||
|
cursor: 'pointer',
|
||||||
|
textAlign: 'left',
|
||||||
|
transition: 'all 0.2s ease',
|
||||||
|
}}
|
||||||
|
onTouchStart={(e) => { e.currentTarget.style.transform = 'scale(0.98)'; }}
|
||||||
|
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
|
||||||
|
>
|
||||||
|
<span style={{ fontWeight: 800, color: brandColor, marginRight: '8px' }}>
|
||||||
|
{opt.option_key}.
|
||||||
|
</span>
|
||||||
|
{displayText}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div style={{ flex: 1 }} />
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={onNext}
|
||||||
|
disabled={!selectedAnswer && !textInput.trim()}
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
padding: '16px',
|
||||||
|
borderRadius: radius.lg,
|
||||||
|
border: 'none',
|
||||||
|
background: (selectedAnswer || textInput.trim())
|
||||||
|
? `linear-gradient(135deg, ${brandColor}, #27AE60)`
|
||||||
|
: 'rgba(0,0,0,0.1)',
|
||||||
|
color: '#FFFFFF',
|
||||||
|
fontSize: '15px',
|
||||||
|
fontWeight: 800,
|
||||||
|
cursor: (selectedAnswer || textInput.trim()) ? 'pointer' : 'default',
|
||||||
|
boxShadow: (selectedAnswer || textInput.trim()) ? `0 4px 15px ${brandColor}40` : 'none',
|
||||||
|
transition: 'all 0.2s ease',
|
||||||
|
}}
|
||||||
|
onTouchStart={(e) => {
|
||||||
|
if (selectedAnswer || textInput.trim()) e.currentTarget.style.transform = 'scale(0.96)';
|
||||||
|
}}
|
||||||
|
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
|
||||||
|
>
|
||||||
|
Далее →
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ============ Результат урока ============
|
||||||
|
const renderResult = () => (
|
||||||
|
<div style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '20px',
|
||||||
|
height: '100%',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
textAlign: 'center',
|
||||||
|
}}>
|
||||||
|
<div style={{ fontSize: '64px' }}>🎉</div>
|
||||||
|
<div style={{ fontSize: '20px', fontWeight: 800, color: textColor, lineHeight: '1.4' }}>
|
||||||
|
{data.resultText || 'Отличная работа!'}
|
||||||
|
</div>
|
||||||
|
{data.correctCount !== undefined && data.totalCount !== undefined && (
|
||||||
|
<div style={{
|
||||||
|
padding: '14px 24px',
|
||||||
|
background: `${brandColor}15`,
|
||||||
|
borderRadius: radius.lg,
|
||||||
|
fontSize: '18px',
|
||||||
|
fontWeight: 800,
|
||||||
|
color: brandColor,
|
||||||
|
}}>
|
||||||
|
{data.correctCount} / {data.totalCount}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div style={{ flex: 1 }} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
// ============ Сводка теста ============
|
||||||
|
const renderTestSummary = () => {
|
||||||
|
const percent = data.totalCount && data.correctCount !== undefined
|
||||||
|
? Math.round((data.correctCount / data.totalCount) * 100)
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '20px',
|
||||||
|
height: '100%',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
textAlign: 'center',
|
||||||
|
}}>
|
||||||
|
<div style={{ fontSize: '56px' }}>📊</div>
|
||||||
|
<div style={{ fontSize: '18px', fontWeight: 800, color: textColor }}>
|
||||||
|
Результат теста
|
||||||
|
</div>
|
||||||
|
<div style={{
|
||||||
|
fontSize: '32px',
|
||||||
|
fontWeight: 900,
|
||||||
|
color: percent >= 70 ? brandColor : '#E74C3C',
|
||||||
|
}}>
|
||||||
|
{data.correctCount} / {data.totalCount}
|
||||||
|
</div>
|
||||||
|
<div style={{ fontSize: '14px', color: subColor }}>
|
||||||
|
{percent}%
|
||||||
|
</div>
|
||||||
|
{data.weakSkill && (
|
||||||
|
<div style={{
|
||||||
|
padding: '12px 18px',
|
||||||
|
background: '#E74C3C10',
|
||||||
|
borderRadius: radius.md,
|
||||||
|
fontSize: '13px',
|
||||||
|
color: textColor,
|
||||||
|
fontWeight: 600,
|
||||||
|
border: '1px solid #E74C3C30',
|
||||||
|
}}>
|
||||||
|
⚠️ Слабое место: {data.weakSkill}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div style={{ flex: 1 }} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ============ Рендер ============
|
||||||
|
const renderContent = () => {
|
||||||
|
switch (data.type) {
|
||||||
|
case 'intro': return renderIntro();
|
||||||
|
case 'question': return renderQuestion();
|
||||||
|
case 'result': return renderResult();
|
||||||
|
case 'test_summary': return renderTestSummary();
|
||||||
|
default: return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ perspective: '1200px', width: '100%', height: '100%' }}>
|
||||||
|
<div style={{
|
||||||
|
...glass({
|
||||||
|
borderRadius: radius.lg,
|
||||||
|
padding: '24px',
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
position: 'relative',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
transform: `rotateY(${rotation}deg)`,
|
||||||
|
transition: isFlipping ? 'transform 0.2s ease-in-out' : 'none',
|
||||||
|
transformStyle: 'preserve-3d',
|
||||||
|
backfaceVisibility: 'hidden',
|
||||||
|
boxShadow: '0 24px 60px rgba(31,38,73,0.20), inset 0 1px 0 rgba(255,255,255,0.85)',
|
||||||
|
}),
|
||||||
|
}}>
|
||||||
|
{/* Прогресс-бар */}
|
||||||
|
<div style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
height: '4px',
|
||||||
|
background: 'rgba(0,0,0,0.05)',
|
||||||
|
borderTopLeftRadius: radius.lg,
|
||||||
|
borderTopRightRadius: radius.lg,
|
||||||
|
overflow: 'hidden',
|
||||||
|
}}>
|
||||||
|
<div style={{
|
||||||
|
width: `${progressPercent}%`,
|
||||||
|
height: '100%',
|
||||||
|
background: `linear-gradient(90deg, ${brandColor}, #27AE60)`,
|
||||||
|
transition: 'width 0.4s ease',
|
||||||
|
}} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Счётчик */}
|
||||||
|
<div style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: '12px',
|
||||||
|
left: '24px',
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: 700,
|
||||||
|
color: subColor,
|
||||||
|
}}>
|
||||||
|
{cardIndex} / {totalCards}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Контент */}
|
||||||
|
<div style={{ flex: 1, paddingTop: '24px', display: 'flex', flexDirection: 'column' }}>
|
||||||
|
{renderContent()}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LessonCard;
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import LessonCard, { type LessonCardData } from './LessonCard';
|
||||||
|
|
||||||
|
interface LessonCardStackProps {
|
||||||
|
cards: LessonCardData[];
|
||||||
|
onComplete: () => void;
|
||||||
|
onAnswer?: (questionId: string, answer: string, hintUsed: boolean) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const LessonCardStack: React.FC<LessonCardStackProps> = ({
|
||||||
|
cards,
|
||||||
|
onComplete,
|
||||||
|
onAnswer,
|
||||||
|
}) => {
|
||||||
|
const [currentIndex, setCurrentIndex] = useState(0);
|
||||||
|
const [rotation, setRotation] = useState(0);
|
||||||
|
const [isFlipping, setIsFlipping] = useState(false);
|
||||||
|
const [selectedAnswer, setSelectedAnswer] = useState<string | null>(null);
|
||||||
|
const [textInput, setTextInput] = useState('');
|
||||||
|
const [hintUsed, setHintUsed] = useState(false);
|
||||||
|
|
||||||
|
const currentCard = cards[currentIndex];
|
||||||
|
const totalCards = cards.length;
|
||||||
|
|
||||||
|
const flip = (nextIndex: number) => {
|
||||||
|
if (isFlipping) return;
|
||||||
|
|
||||||
|
setIsFlipping(true);
|
||||||
|
setRotation(180);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
setCurrentIndex(nextIndex);
|
||||||
|
setRotation(360);
|
||||||
|
|
||||||
|
setSelectedAnswer(null);
|
||||||
|
setTextInput('');
|
||||||
|
setHintUsed(false);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
setRotation(0);
|
||||||
|
setIsFlipping(false);
|
||||||
|
}, 200);
|
||||||
|
}, 200);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNext = async () => {
|
||||||
|
if (currentCard.type === 'question') {
|
||||||
|
const answer = currentCard.questionType === 'production' ? textInput : (selectedAnswer || '');
|
||||||
|
if (onAnswer && currentCard.questionId) {
|
||||||
|
await onAnswer(currentCard.questionId, answer, hintUsed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentIndex >= totalCards - 1) {
|
||||||
|
onComplete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
flip(currentIndex + 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleStartLesson = () => {
|
||||||
|
if (currentIndex < totalCards - 1) {
|
||||||
|
flip(currentIndex + 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleShowHint = () => {
|
||||||
|
setHintUsed(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
height: '100%',
|
||||||
|
padding: '16px',
|
||||||
|
}}>
|
||||||
|
<div style={{ flex: 1, position: 'relative' }}>
|
||||||
|
<LessonCard
|
||||||
|
data={currentCard}
|
||||||
|
cardIndex={currentIndex + 1}
|
||||||
|
totalCards={totalCards}
|
||||||
|
selectedAnswer={selectedAnswer}
|
||||||
|
textInput={textInput}
|
||||||
|
hintUsed={hintUsed}
|
||||||
|
isFlipping={isFlipping}
|
||||||
|
rotation={rotation}
|
||||||
|
onSelectAnswer={setSelectedAnswer}
|
||||||
|
onTextChange={setTextInput}
|
||||||
|
onNext={handleNext}
|
||||||
|
onShowHint={handleShowHint}
|
||||||
|
onStartLesson={handleStartLesson}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LessonCardStack;
|
||||||
@@ -19,6 +19,8 @@ import {
|
|||||||
import TeacherMenuModal from '../components/TeacherMenuModal';
|
import TeacherMenuModal from '../components/TeacherMenuModal';
|
||||||
import TypingModal from '../components/TypingModal';
|
import TypingModal from '../components/TypingModal';
|
||||||
import PronunciationModal from '../components/PronunciationModal';
|
import PronunciationModal from '../components/PronunciationModal';
|
||||||
|
import LessonCardStack from '../components/LessonCardStack';
|
||||||
|
import { type LessonCardData } from '../components/LessonCard';
|
||||||
|
|
||||||
interface TeacherMessage {
|
interface TeacherMessage {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -85,6 +87,11 @@ const TeacherChatPage: React.FC = () => {
|
|||||||
const [showTyping, setShowTyping] = useState(false);
|
const [showTyping, setShowTyping] = useState(false);
|
||||||
const [showPronunciation, setShowPronunciation] = useState(false);
|
const [showPronunciation, setShowPronunciation] = useState(false);
|
||||||
|
|
||||||
|
// 🔧 НОВОЕ (22.09.2026): режим карточек для уроков.
|
||||||
|
// Если lessonCards !== null → рендерим LessonCardStack вместо ленты.
|
||||||
|
const [lessonCards, setLessonCards] = useState<LessonCardData[] | null>(null);
|
||||||
|
const [cardSessionId, setCardSessionId] = useState<number | null>(null);
|
||||||
|
|
||||||
const [explanationData, setExplanationData] = useState<{
|
const [explanationData, setExplanationData] = useState<{
|
||||||
wrongAnswer: string;
|
wrongAnswer: string;
|
||||||
correctAnswer: string;
|
correctAnswer: string;
|
||||||
@@ -381,44 +388,41 @@ const TeacherChatPage: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
const data = await teacherStart();
|
const data = await teacherStart();
|
||||||
|
|
||||||
if (data.session_id) setSessionId(data.session_id);
|
if (data.session_id) {
|
||||||
|
setSessionId(data.session_id);
|
||||||
|
setCardSessionId(data.session_id);
|
||||||
|
}
|
||||||
if (data.lesson_id) setCurrentLessonId(data.lesson_id);
|
if (data.lesson_id) setCurrentLessonId(data.lesson_id);
|
||||||
if (data.topic_id) setCurrentTopicId(data.topic_id);
|
if (data.topic_id) setCurrentTopicId(data.topic_id);
|
||||||
if (data.topic_name) setCurrentTopicName(data.topic_name);
|
if (data.topic_name) setCurrentTopicName(data.topic_name);
|
||||||
|
|
||||||
|
// 🔧 НОВОЕ (22.09.2026): собираем массив карточек.
|
||||||
if (data.question) {
|
if (data.question) {
|
||||||
const lessonCardMsg: TeacherMessage = {
|
const cards: LessonCardData[] = [];
|
||||||
id: idRef.current++,
|
|
||||||
type: 'bot',
|
|
||||||
text: data.text,
|
|
||||||
topicId: data.topic_id,
|
|
||||||
topicName: data.topic_name,
|
|
||||||
hasPolishText: hasPolishContent(data.text),
|
|
||||||
isLessonCard: true,
|
|
||||||
};
|
|
||||||
setMessages(prev => [...prev, lessonCardMsg]);
|
|
||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 400));
|
// 1. Титульная
|
||||||
|
cards.push({
|
||||||
|
type: 'intro',
|
||||||
|
levelCode: 'A1', // TODO: подтянуть из data
|
||||||
|
topicName: data.topic_name || '',
|
||||||
|
lessonNumber: 1, // TODO: подтянуть из data
|
||||||
|
lessonTitle: data.text.split('\n')[0] || '',
|
||||||
|
explanation: data.text, // временно весь text
|
||||||
|
examples: [],
|
||||||
|
});
|
||||||
|
|
||||||
const questionMsg: TeacherMessage = {
|
// 2. Первый вопрос
|
||||||
id: idRef.current++,
|
cards.push({
|
||||||
type: 'bot',
|
type: 'question',
|
||||||
text: getLocalized(data.question.question, 'prompt'),
|
|
||||||
isQuestion: true,
|
|
||||||
questionType: data.question.question.question_type,
|
|
||||||
questionId: data.question.question.question_id,
|
questionId: data.question.question.question_id,
|
||||||
|
questionType: data.question.question.question_type,
|
||||||
|
prompt: getLocalized(data.question.question, 'prompt'),
|
||||||
options: data.question.options,
|
options: data.question.options,
|
||||||
optionsLanguage: data.question.question.options_language || 'pl',
|
optionsLanguage: data.question.question.options_language || 'pl',
|
||||||
sessionId: data.session_id,
|
});
|
||||||
lessonId: data.lesson_id,
|
|
||||||
topicId: data.topic_id,
|
|
||||||
topicName: data.topic_name,
|
|
||||||
questionIndex: data.question_index,
|
|
||||||
totalQuestions: data.total_questions,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
setLessonCards(cards);
|
||||||
setCurrentQuestionId(data.question.question.question_id);
|
setCurrentQuestionId(data.question.question.question_id);
|
||||||
setMessages(prev => [...prev, questionMsg]);
|
|
||||||
setIsStarted(true);
|
setIsStarted(true);
|
||||||
} else {
|
} else {
|
||||||
const botMessage: TeacherMessage = {
|
const botMessage: TeacherMessage = {
|
||||||
@@ -438,6 +442,47 @@ const TeacherChatPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 🔧 НОВОЕ (22.09.2026): обработка ответа в режиме карточек.
|
||||||
|
const handleCardAnswer = async (questionId: string, answer: string, _hintUsed: boolean) => {
|
||||||
|
if (!cardSessionId) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const timeTaken = Date.now() - startTimeRef.current;
|
||||||
|
startTimeRef.current = Date.now();
|
||||||
|
|
||||||
|
const data = await teacherAnswer(cardSessionId, questionId, answer, timeTaken);
|
||||||
|
|
||||||
|
// Если сессия завершена — добавляем result-карточку
|
||||||
|
if (data.session_completed && lessonCards) {
|
||||||
|
const stats = data.session_stats || { total: 0, correct_count: 0 };
|
||||||
|
const resultCard: LessonCardData = {
|
||||||
|
type: 'result',
|
||||||
|
resultText: data.reaction || 'Отличная работа!',
|
||||||
|
correctCount: stats.correct_count,
|
||||||
|
totalCount: stats.total,
|
||||||
|
};
|
||||||
|
setLessonCards(prev => prev ? [...prev, resultCard] : [resultCard]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если есть следующий вопрос — добавляем карточку
|
||||||
|
if (data.question && lessonCards) {
|
||||||
|
const nextCard: LessonCardData = {
|
||||||
|
type: 'question',
|
||||||
|
questionId: data.question.question.question_id,
|
||||||
|
questionType: data.question.question.question_type,
|
||||||
|
prompt: getLocalized(data.question.question, 'prompt'),
|
||||||
|
options: data.question.options,
|
||||||
|
optionsLanguage: data.question.question.options_language || 'pl',
|
||||||
|
};
|
||||||
|
setLessonCards(prev => prev ? [...prev, nextCard] : [nextCard]);
|
||||||
|
setCurrentQuestionId(data.question.question.question_id);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error in handleCardAnswer:', e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleAnswer = async (answer: string) => {
|
const handleAnswer = async (answer: string) => {
|
||||||
if (!sessionId || !currentQuestionId || isLoading) return;
|
if (!sessionId || !currentQuestionId || isLoading) return;
|
||||||
|
|
||||||
@@ -1067,7 +1112,21 @@ const TeacherChatPage: React.FC = () => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Сообщения */}
|
{/* 🔧 НОВОЕ (22.09.2026): если урок в режиме карточек — рендерим LessonCardStack */}
|
||||||
|
{lessonCards ? (
|
||||||
|
<div style={{ flex: 1, minHeight: 0 }}>
|
||||||
|
<LessonCardStack
|
||||||
|
cards={lessonCards}
|
||||||
|
onAnswer={handleCardAnswer}
|
||||||
|
onComplete={() => {
|
||||||
|
setLessonCards(null);
|
||||||
|
setCardSessionId(null);
|
||||||
|
setIsStarted(false);
|
||||||
|
handleStart();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
<div style={{
|
<div style={{
|
||||||
flex: 1,
|
flex: 1,
|
||||||
overflowY: 'auto',
|
overflowY: 'auto',
|
||||||
@@ -1388,6 +1447,7 @@ const TeacherChatPage: React.FC = () => {
|
|||||||
|
|
||||||
<div ref={messagesEndRef} />
|
<div ref={messagesEndRef} />
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{isQuestionActive && (
|
{isQuestionActive && (
|
||||||
<div style={{
|
<div style={{
|
||||||
|
|||||||
Reference in New Issue
Block a user