diff --git a/src/App.tsx b/src/App.tsx index 3b47602..f3e7157 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -18,6 +18,8 @@ import PracticeViewPage from './pages/PracticeViewPage'; import TeacherChatPage from './pages/TeacherChatPage'; import TypingPage from './pages/TypingPage'; import AdminDashboardModal from './components/AdminDashboardModal'; +import LearningPage from './pages/LearningPage'; +import LecturesPage from './pages/LecturesPage'; // 🔧 ФИКС (25.09.2026): DEAD_CODE_GET_IS_ADMIN_FALLBACK — // getIsAdmin больше не нужен: registerUser гарантирует is_admin: boolean. import { registerUser, trackDailyLogin } from './api'; @@ -244,6 +246,8 @@ function AppContent() { } /> } /> } /> + } /> + } /> {/* Дашборд админа — открывается через событие "open-dashboard" из MenuPage */} diff --git a/src/api.ts b/src/api.ts index d88c742..25e71a7 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1352,4 +1352,86 @@ export interface WrongBecauseItem { } export const getWrongBecause = (): Promise<{ items: WrongBecauseItem[] }> => - fetchAPI('/admin/content/wrong-because'); \ No newline at end of file + fetchAPI('/admin/content/wrong-because'); + +// ============ LECTURES (Лекции) ============ + +export interface LectureListItem { + id: number; + title_pl: string; + title_ru: string; + title_uk: string; + title_en: string; + description_pl: string; + description_ru: string; + description_uk: string; + description_en: string; + file_type: string; + file_size_kb: number; + order_number: number; +} + +export interface LecturesListResponse { + level: string; + lectures: LectureListItem[]; +} + +export interface LectureDetail { + id: number; + level_code: string; + title_pl: string; + title_ru: string; + title_uk: string; + title_en: string; + description_pl: string; + description_ru: string; + description_uk: string; + description_en: string; + file_type: string; + file_size_kb: number; + file_url: string; + order_number: number; +} + +/** + * Получить список лекций для уровня. + * Если level не передан — бэк возьмёт из профиля юзера. + */ +export const getLectures = (level?: string): Promise => { + const levelParam = level ? `?level=${encodeURIComponent(level)}` : ''; + return fetchAPI(`/learning/lectures${levelParam}`); +}; + +/** + * Получить метаданные одной лекции. + */ +export const getLecture = (lectureId: number): Promise => + fetchAPI(`/learning/lecture/${lectureId}`); + +/** + * Скачать файл лекции. + * Возвращает blob, который можно сохранить. + */ +export const downloadLecture = async (lectureId: number): Promise => { + const initData = getInitData(); + + if (!initData) { + throw new Error('Telegram initData недоступен. Откройте приложение через Telegram.'); + } + + const url = `${API_BASE}/learning/lecture/${lectureId}/download`; + + const res = await fetchWithTimeout(url, { + method: 'GET', + headers: { + 'Authorization': `tma ${initData}`, + }, + }); + + if (!res.ok) { + const errorText = await res.text(); + throw new Error(`API Error: ${res.status} - ${errorText}`); + } + + return res.blob(); +}; \ No newline at end of file diff --git a/src/i18n/translations.ts b/src/i18n/translations.ts index faf490a..df1eeda 100644 --- a/src/i18n/translations.ts +++ b/src/i18n/translations.ts @@ -160,6 +160,10 @@ export const translations: Record> = { teacherMenuAdditional: "Dodatkowe", // 🔧 НОВОЕ: подсказка в обратном порядке tryReverseOrder: "Spróbuj w odwrotnej kolejności", + // ============ Learning (26.09.2026) ============ + learning: "Nauka", + lectures: "Wykłady", + lessons: "Lekcje", // ============ Onboarding ============ onboardingStep1Title: "Witaj! Jestem Marek.", onboardingStep1Text: "Jestem twoim osobistym nauczycielem polskiego.\nBędę prowadzić cię krok po kroku, od pierwszego słowa do swobodnej rozmowy.", @@ -392,6 +396,10 @@ export const translations: Record> = { teacherMenuAdditional: "Дополнительное", // 🔧 НОВОЕ: подсказка в обратном порядке tryReverseOrder: "Попробуй в обратном порядке", + // ============ Learning (26.09.2026) ============ + learning: "Обучение", + lectures: "Лекции", + lessons: "Уроки", // ============ Onboarding ============ onboardingStep1Title: "Привет! Я Марек.", onboardingStep1Text: "Я твой личный учитель польского.\nБуду вести тебя шаг за шагом, от первого слова до свободного разговора.", @@ -624,6 +632,10 @@ export const translations: Record> = { teacherMenuAdditional: "Додаткове", // 🔧 НОВОЕ: подсказка в обратном порядке tryReverseOrder: "Спробуй у зворотному порядку", + // ============ Learning (26.09.2026) ============ + learning: "Навчання", + lectures: "Лекції", + lessons: "Уроки", // ============ Onboarding ============ onboardingStep1Title: "Привіт! Я Марек.", onboardingStep1Text: "Я твій особистий вчитель польської.\nБуду вести тебе крок за кроком, від першого слова до вільної розмови.", @@ -856,6 +868,10 @@ export const translations: Record> = { teacherMenuAdditional: "Additional", // 🔧 НОВОЕ: подсказка в обратном порядке tryReverseOrder: "Try the reverse order", + // ============ Learning (26.09.2026) ============ + learning: "Learning", + lectures: "Lectures", + lessons: "Lessons", // ============ Onboarding ============ onboardingStep1Title: "Hey! I'm Marek.", onboardingStep1Text: "I'm your personal Polish teacher.\nI'll guide you step by step, from your very first word to a real conversation.", diff --git a/src/pages/LearningPage.tsx b/src/pages/LearningPage.tsx new file mode 100644 index 0000000..bee01c4 --- /dev/null +++ b/src/pages/LearningPage.tsx @@ -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 ( +
+
+
+ +
+ + {/* Заголовок с кнопкой назад */} +
+ +

+ 🎓 {t('learning') || 'Обучение'} +

+
+ + {/* Две карточки — Лекции и Уроки */} +
+ + {/* Лекции */} + + + {/* Уроки */} + + +
+ +
+ Filwords PL © 2026 +
+
+
+ ); +}; + +export default LearningPage; \ No newline at end of file diff --git a/src/pages/LecturesPage.tsx b/src/pages/LecturesPage.tsx new file mode 100644 index 0000000..a4d5b26 --- /dev/null +++ b/src/pages/LecturesPage.tsx @@ -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([]); + const [level, setLevel] = useState('A1'); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const [activeLecture, setActiveLecture] = useState(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 ( +
+
+ +
+ + {/* Заголовок */} +
+ +

+ {activeLecture.title_pl} +

+ +
+ + {/* Просмотр */} +
+ {activeLecture.file_type === 'pdf' ? ( +