📄 Learning: раздел «Обучение» с 2 подразделами

Новое:
- Раздел «Обучение» (бывший «Учитель»)
- 2 подраздела:
  - 📄 Лекции — список по уровню, PDF viewer, скачивание
  - 📚 Уроки — бывший «Учитель» (работает как раньше)
- api.ts: getLectures, getLecture, downloadLecture
- App.tsx: роуты /learning, /lectures
- MenuPage.tsx: переименование «Учитель» → «Обучение»
- translations.ts: ключи learning, lectures, lessons
- LearningPage.tsx: новая страница с 2 карточками
- LecturesPage.tsx: список + viewer + скачивание

Пока лекций нет — показывается заглушка «Лекции в разработке».
This commit is contained in:
2026-09-26 19:47:57 +03:00
parent 08b030a5fd
commit 779d96919a
6 changed files with 692 additions and 4 deletions
+190
View File
@@ -0,0 +1,190 @@
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useLanguage } from '../i18n/LanguageContext';
import { fonts, radius } from '../styles/theme';
import { trackTeacherMenuOpened } from '../api';
/**
* LearningPage — раздел «Обучение» с двумя подразделами:
* 1. 📄 Лекции (архивы PDF/HTML)
* 2. 📚 Уроки (бывший «Учитель»)
*/
const LearningPage: React.FC = () => {
const navigate = useNavigate();
const { t } = useLanguage();
const teacherColor = '#8B5CF6';
const lectureColor = '#4FA9E8';
const textColor = '#1A1A2E';
const subColor = '#6B7280';
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,
});
useEffect(() => {
trackTeacherMenuOpened().catch(() => {});
}, []);
const getCardStyle = (): React.CSSProperties => ({
padding: '24px',
borderRadius: radius.lg,
border: '1px solid rgba(255,255,255,0.7)',
background: 'rgba(255,255,255,0.55)',
backdropFilter: 'blur(24px) saturate(180%)',
WebkitBackdropFilter: 'blur(24px) saturate(180%)',
cursor: 'pointer',
transition: 'all 0.2s ease',
boxShadow: '0 6px 20px rgba(31,38,73,0.08), inset 0 1px 0 rgba(255,255,255,0.85)',
display: 'flex',
alignItems: 'center',
gap: '16px',
textAlign: 'left',
});
return (
<div style={{
minHeight: '100vh',
background: '#F4F5F7',
color: textColor,
fontFamily: fonts.main,
display: 'flex',
flexDirection: 'column',
padding: '24px',
position: 'relative',
overflow: 'hidden',
}}>
<div style={{ position: 'fixed', top: '-120px', left: '-90px', width: '320px', height: '320px', borderRadius: '50%', background: teacherColor, opacity: 0.25, filter: 'blur(90px)', pointerEvents: 'none', zIndex: 0 }} />
<div style={{ position: 'fixed', bottom: '-90px', right: '-40px', width: '260px', height: '260px', borderRadius: '50%', background: lectureColor, opacity: 0.22, filter: 'blur(90px)', pointerEvents: 'none', zIndex: 0 }} />
<div style={{ position: 'relative', zIndex: 1, display: 'flex', flexDirection: 'column', flex: 1 }}>
{/* Заголовок с кнопкой назад */}
<div style={{
display: 'flex',
alignItems: 'center',
gap: '10px',
marginBottom: '32px',
}}>
<button
onClick={() => navigate('/menu')}
style={{
...glass({ padding: '10px 14px', borderRadius: radius.md }),
color: textColor,
fontSize: '14px',
fontWeight: 600,
cursor: 'pointer',
}}
>
←
</button>
<h1 style={{
fontSize: '24px',
fontWeight: 800,
margin: 0,
color: textColor,
}}>
🎓 {t('learning') || 'Обучение'}
</h1>
</div>
{/* Две карточки — Лекции и Уроки */}
<div style={{
display: 'flex',
flexDirection: 'column',
gap: '16px',
flex: 1,
}}>
{/* Лекции */}
<button
onClick={() => navigate('/lectures')}
style={getCardStyle()}
onTouchStart={(e) => { e.currentTarget.style.transform = 'scale(0.98)'; }}
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
>
<div style={{
fontSize: '48px',
flexShrink: 0,
}}>
📄
</div>
<div style={{ flex: 1 }}>
<div style={{
fontSize: '20px',
fontWeight: 800,
color: textColor,
marginBottom: '4px',
}}>
{t('lectures') || 'Лекции'}
</div>
<div style={{
fontSize: '14px',
color: subColor,
}}>
{t('lecturesDescription') || 'Тексты, PDF, шпаргалки по уровням'}
</div>
</div>
<div style={{
fontSize: '20px',
color: lectureColor,
flexShrink: 0,
}}>
→
</div>
</button>
{/* Уроки */}
<button
onClick={() => navigate('/teacher')}
style={getCardStyle()}
onTouchStart={(e) => { e.currentTarget.style.transform = 'scale(0.98)'; }}
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
>
<div style={{
fontSize: '48px',
flexShrink: 0,
}}>
📚
</div>
<div style={{ flex: 1 }}>
<div style={{
fontSize: '20px',
fontWeight: 800,
color: textColor,
marginBottom: '4px',
}}>
{t('lessons') || 'Уроки'}
</div>
<div style={{
fontSize: '14px',
color: subColor,
}}>
{t('lessonsDescription') || 'Темы, уроки, задания и тесты'}
</div>
</div>
<div style={{
fontSize: '20px',
color: teacherColor,
flexShrink: 0,
}}>
→
</div>
</button>
</div>
<div style={{ textAlign: 'center', marginTop: '24px', color: '#9CA3AF', fontSize: '12px' }}>
Filwords PL © 2026
</div>
</div>
</div>
);
};
export default LearningPage;
+390
View File
@@ -0,0 +1,390 @@
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useLanguage } from '../i18n/LanguageContext';
import { fonts, radius } from '../styles/theme';
import { getLectures, getLecture, downloadLecture, type LectureListItem, type LectureDetail } from '../api';
/**
* LecturesPage — список лекций по уровню пользователя.
* Открывает PDF/HTML в viewer, даёт скачать.
*/
const LecturesPage: React.FC = () => {
const navigate = useNavigate();
const { t, language } = useLanguage();
const [lectures, setLectures] = useState<LectureListItem[]>([]);
const [level, setLevel] = useState('A1');
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [activeLecture, setActiveLecture] = useState<LectureDetail | null>(null);
const [downloading, setDownloading] = useState(false);
const brandColor = '#2ECC71';
const lectureColor = '#4FA9E8';
const textColor = '#1A1A2E';
const subColor = '#6B7280';
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,
});
useEffect(() => {
getLectures()
.then((data) => {
setLectures(data.lectures || []);
setLevel(data.level || 'A1');
setLoading(false);
})
.catch((e) => {
console.error('Failed to load lectures:', e);
setError(t('loadError') || 'Ошибка загрузки');
setLoading(false);
});
}, []);
const getTitle = (lecture: LectureListItem): string => {
const field = `title_${language}` as keyof LectureListItem;
return (lecture[field] as string) || lecture.title_en || lecture.title_pl || '';
};
const getDescription = (lecture: LectureListItem): string => {
const field = `description_${language}` as keyof LectureListItem;
return (lecture[field] as string) || lecture.description_en || lecture.description_pl || '';
};
const handleOpenLecture = async (lectureId: number) => {
try {
const detail = await getLecture(lectureId);
setActiveLecture(detail);
} catch (e) {
console.error('Failed to open lecture:', e);
alert(t('loadError') || 'Ошибка загрузки');
}
};
const handleDownload = async () => {
if (!activeLecture || downloading) return;
setDownloading(true);
try {
const blob = await downloadLecture(activeLecture.id);
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${activeLecture.title_pl || 'lecture'}.${activeLecture.file_type}`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
} catch (e) {
console.error('Download failed:', e);
alert(t('loadError') || 'Ошибка скачивания');
} finally {
setDownloading(false);
}
};
// ============ VIEWER ЛЕКЦИИ ============
if (activeLecture) {
return (
<div style={{
minHeight: '100vh',
background: '#F4F5F7',
color: textColor,
fontFamily: fonts.main,
display: 'flex',
flexDirection: 'column',
position: 'relative',
overflow: 'hidden',
}}>
<div style={{ position: 'fixed', top: '-120px', left: '-90px', width: '320px', height: '320px', borderRadius: '50%', background: lectureColor, opacity: 0.20, filter: 'blur(90px)', pointerEvents: 'none', zIndex: 0 }} />
<div style={{ position: 'relative', zIndex: 1, display: 'flex', flexDirection: 'column', flex: 1, padding: '16px' }}>
{/* Заголовок */}
<div style={{
display: 'flex',
alignItems: 'center',
gap: '10px',
marginBottom: '16px',
flexShrink: 0,
}}>
<button
onClick={() => setActiveLecture(null)}
style={{
...glass({ padding: '8px 14px', borderRadius: radius.sm }),
color: textColor,
fontSize: '13px',
fontWeight: 600,
cursor: 'pointer',
}}
>
←
</button>
<h1 style={{
fontSize: '16px',
fontWeight: 800,
margin: 0,
color: textColor,
flex: 1,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}>
{activeLecture.title_pl}
</h1>
<button
onClick={handleDownload}
disabled={downloading}
style={{
...glass({ padding: '8px 14px', borderRadius: radius.sm }),
color: lectureColor,
fontSize: '13px',
fontWeight: 700,
cursor: downloading ? 'default' : 'pointer',
opacity: downloading ? 0.6 : 1,
}}
>
{downloading ? '...' : '⬇'}
</button>
</div>
{/* Просмотр */}
<div style={{
flex: 1,
borderRadius: radius.lg,
background: 'rgba(255,255,255,0.85)',
border: '1px solid rgba(0,0,0,0.06)',
overflow: 'hidden',
boxShadow: '0 8px 32px rgba(31,38,73,0.10)',
minHeight: 0,
}}>
{activeLecture.file_type === 'pdf' ? (
<iframe
src={`https://api.filwordspl.com${activeLecture.file_url}`}
style={{
width: '100%',
height: '100%',
border: 'none',
}}
title={activeLecture.title_pl}
/>
) : activeLecture.file_type === 'html' ? (
<iframe
src={`https://api.filwordspl.com${activeLecture.file_url}`}
style={{
width: '100%',
height: '100%',
border: 'none',
}}
title={activeLecture.title_pl}
/>
) : (
<div style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
padding: '40px',
textAlign: 'center',
}}>
<div style={{ fontSize: '64px', marginBottom: '16px' }}>📄</div>
<p style={{ fontSize: '16px', color: subColor, marginBottom: '20px' }}>
{t('lecturePreviewNotAvailable') || 'Просмотр недоступен для этого формата'}
</p>
<button
onClick={handleDownload}
disabled={downloading}
style={{
padding: '14px 28px',
borderRadius: radius.lg,
border: 'none',
background: `linear-gradient(135deg, ${lectureColor}, #3B82F6)`,
color: '#FFFFFF',
fontSize: '15px',
fontWeight: 700,
cursor: downloading ? 'default' : 'pointer',
opacity: downloading ? 0.6 : 1,
}}
>
{downloading ? '...' : `⬇ ${t('download') || 'Скачать'}`}
</button>
</div>
)}
</div>
</div>
</div>
);
}
// ============ СПИСОК ЛЕКЦИЙ ============
return (
<div style={{
minHeight: '100vh',
background: '#F4F5F7',
color: textColor,
fontFamily: fonts.main,
display: 'flex',
flexDirection: 'column',
padding: '24px',
position: 'relative',
overflow: 'hidden',
}}>
<div style={{ position: 'fixed', top: '-120px', left: '-90px', width: '320px', height: '320px', borderRadius: '50%', background: lectureColor, opacity: 0.20, filter: 'blur(90px)', pointerEvents: 'none', zIndex: 0 }} />
<div style={{ position: 'relative', zIndex: 1, display: 'flex', flexDirection: 'column', flex: 1 }}>
{/* Заголовок */}
<div style={{
display: 'flex',
alignItems: 'center',
gap: '10px',
marginBottom: '24px',
}}>
<button
onClick={() => navigate('/learning')}
style={{
...glass({ padding: '10px 14px', borderRadius: radius.md }),
color: textColor,
fontSize: '14px',
fontWeight: 600,
cursor: 'pointer',
}}
>
←
</button>
<h1 style={{
fontSize: '22px',
fontWeight: 800,
margin: 0,
color: textColor,
flex: 1,
}}>
📄 {t('lectures') || 'Лекции'}
</h1>
<span style={{
...glass({ padding: '6px 12px', borderRadius: radius.sm }),
fontSize: '14px',
fontWeight: 800,
color: brandColor,
}}>
{level}
</span>
</div>
{/* Список */}
{loading ? (
<div style={{ textAlign: 'center', padding: '40px', color: subColor }}>
{t('loading') || 'Загрузка...'}
</div>
) : error ? (
<div style={{ textAlign: 'center', padding: '40px', color: '#E74C3C' }}>
⚠️ {error}
</div>
) : lectures.length === 0 ? (
<div style={{
textAlign: 'center',
padding: '60px 20px',
color: subColor,
animation: 'fadeIn 0.3s ease',
}}>
<div style={{ fontSize: '64px', marginBottom: '16px' }}>📭</div>
<p style={{ fontSize: '16px', marginBottom: '8px', fontWeight: 600 }}>
{t('lecturesEmpty') || 'Лекции в разработке'}
</p>
<p style={{ fontSize: '14px', opacity: 0.7 }}>
{t('lecturesEmptyHint') || 'Скоро здесь появятся материалы для уровня'} {level}
</p>
</div>
) : (
<div style={{
display: 'flex',
flexDirection: 'column',
gap: '12px',
}}>
{lectures.map((lecture) => (
<button
key={lecture.id}
onClick={() => handleOpenLecture(lecture.id)}
style={{
padding: '18px 20px',
borderRadius: radius.lg,
border: '1px solid rgba(255,255,255,0.7)',
background: 'rgba(255,255,255,0.55)',
backdropFilter: 'blur(24px) saturate(180%)',
WebkitBackdropFilter: 'blur(24px) saturate(180%)',
boxShadow: '0 6px 20px rgba(31,38,73,0.08), inset 0 1px 0 rgba(255,255,255,0.85)',
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
gap: '16px',
textAlign: 'left',
transition: 'all 0.2s ease',
}}
onTouchStart={(e) => { e.currentTarget.style.transform = 'scale(0.98)'; }}
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
>
<div style={{
fontSize: '32px',
flexShrink: 0,
}}>
{lecture.file_type === 'pdf' ? '📕' : lecture.file_type === 'html' ? '🌐' : '📄'}
</div>
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{
fontSize: '16px',
fontWeight: 700,
color: textColor,
marginBottom: '4px',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}>
{getTitle(lecture)}
</div>
{getDescription(lecture) && (
<div style={{
fontSize: '13px',
color: subColor,
marginBottom: '4px',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}>
{getDescription(lecture)}
</div>
)}
<div style={{
fontSize: '11px',
color: subColor,
opacity: 0.7,
}}>
{lecture.file_type.toUpperCase()} · {lecture.file_size_kb} KB
</div>
</div>
<div style={{
fontSize: '20px',
color: lectureColor,
flexShrink: 0,
}}>
→
</div>
</button>
))}
</div>
)}
<div style={{ textAlign: 'center', marginTop: '24px', color: '#9CA3AF', fontSize: '12px' }}>
Filwords PL © 2026
</div>
</div>
</div>
);
};
export default LecturesPage;
+9 -3
View File
@@ -263,7 +263,10 @@ const MenuPage: React.FC = () => {
// 🔧 ОБНОВЛЕНО: убраны typingHandlers и pronunciationHandlers —
// эти разделы теперь живут в меню учителя (☰ → Произношение / Печать).
const teacherHandlers = makeButtonHandlers('teacher', () => navigate('/teacher'));
// 🔧 ОБНОВЛЕНО (26.09.2026): teacherHandlers → learningHandlers.
// Кнопка 🎓 теперь ведёт на /learning (новый раздел «Обучение» с лекциями),
// а не на /teacher (старый чат-учитель).
const learningHandlers = makeButtonHandlers('teacher', () => navigate('/learning'));
const gamesHandlers = makeButtonHandlers('games', () => setShowGamesModal(true));
const leaderboardHandlers = makeButtonHandlers('leaderboard', () => navigate('/leaderboard'));
const supportHandlers = makeButtonHandlers('support', () => setShowSupportModal(true));
@@ -826,8 +829,11 @@ const MenuPage: React.FC = () => {
overflow: 'auto',
WebkitOverflowScrolling: 'touch',
}}>
<button {...teacherHandlers} style={getButtonStyle('teacher', true)}>
<span>🎓</span> {t('teacher')}
{/* 🔧 ОБНОВЛЕНО (26.09.2026): кнопка 🎓 теперь ведёт на /learning.
Иконка и стиль остались те же (teacher-палитра),
чтобы не менять визуал. */}
<button {...learningHandlers} style={getButtonStyle('teacher', true)}>
<span>🎓</span> {t('learning') || 'Обучение'}
</button>
<button {...gamesHandlers} style={getButtonStyle('play')}>
<span>🎮</span> {t('games') || 'Games'}