feat(haptic): вибрация на 7 страницах — уроки, тест, практика, учитель, лекции, произношение

- LessonsPage: selection() на выбор уровня/темы, кнопка назад
- LessonViewPage: selection() на ответ, heavy() на завершение урока
- TestViewPage: selection() на ответ, heavy() на завершение, medium() на примеры/практику
- PracticeViewPage: selection() на ответ, heavy() на завершение практики
- TeacherChatPage: medium() на старт, success()/error() на ответ учителя
- LecturesPage: selection() на открытие, medium() на скачивание
- PronunciationPage: selection() на тап по слову, light() на следующее

Глобальный useGlobalHaptic в App.tsx вешает light() на все кнопки.
На кнопках с явным haptic — data-no-haptic="true" против двойной вибрации.
This commit is contained in:
2026-10-01 15:54:27 +03:00
parent 38c16f9a79
commit cae2443dda
7 changed files with 137 additions and 27 deletions
+20 -2
View File
@@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom';
import { Document, Page, pdfjs } from 'react-pdf';
import { useLanguage } from '../i18n/LanguageContext';
import { fonts, radius } from '../styles/theme';
import { haptic } from '../haptic';
import { getLectures, type LectureListItem } from '../api';
// pdf.js worker + cMaps (для кириллицы и польских букв)
@@ -78,6 +79,8 @@ const LecturesPage: React.FC = () => {
};
const handleOpenLecture = (lecture: LectureListItem) => {
// 🔧 ФИКС (01.10.2026): haptic_lectures — открытие лекции
haptic.selection();
setActiveLecture(lecture);
setPageNumber(1);
setNumPages(0);
@@ -94,6 +97,8 @@ const LecturesPage: React.FC = () => {
};
const handleDownloadLecture = (lecture: LectureListItem) => {
// 🔧 ФИКС (01.10.2026): haptic_lectures — скачивание
haptic.medium();
const url = getFileUrl(lecture);
if (window.Telegram?.WebApp?.downloadFile) {
@@ -205,6 +210,7 @@ const LecturesPage: React.FC = () => {
}}
>
<button
data-no-haptic="true"
onClick={() => handleOpenLecture(lecture)}
style={{
flex: 1,
@@ -238,6 +244,7 @@ const LecturesPage: React.FC = () => {
</button>
<button
data-no-haptic="true"
onClick={() => handleDownloadLecture(lecture)}
style={{
width: '40px',
@@ -320,6 +327,7 @@ const LecturesPage: React.FC = () => {
{activeLecture.title}
</div>
<button
data-no-haptic="true"
onClick={() => handleDownloadLecture(activeLecture)}
style={{
padding: '6px 12px',
@@ -411,7 +419,12 @@ const LecturesPage: React.FC = () => {
marginTop: '12px',
}}>
<button
onClick={() => setPageNumber(p => Math.max(1, p - 1))}
data-no-haptic="true"
onClick={() => {
// 🔧 ФИКС (01.10.2026): haptic_lectures — пагинация PDF
haptic.light();
setPageNumber(p => Math.max(1, p - 1));
}}
disabled={pageNumber <= 1}
style={{
padding: '8px 16px',
@@ -436,7 +449,12 @@ const LecturesPage: React.FC = () => {
{pageNumber} / {numPages}
</div>
<button
onClick={() => setPageNumber(p => Math.min(numPages, p + 1))}
data-no-haptic="true"
onClick={() => {
// 🔧 ФИКС (01.10.2026): haptic_lectures — пагинация PDF
haptic.light();
setPageNumber(p => Math.min(numPages, p + 1));
}}
disabled={pageNumber >= numPages}
style={{
padding: '8px 16px',
+9
View File
@@ -3,6 +3,7 @@ import { useNavigate, useParams } from 'react-router-dom';
import { useLanguage } from '../i18n/LanguageContext';
import { useLocalized } from '../hooks/useLocalized';
import { fonts, radius } from '../styles/theme';
import { haptic } from '../haptic';
import { getLearningLesson, startLearningSession, saveLearningAnswer, completeLearningSession } from '../api';
interface QuestionOption {
@@ -118,6 +119,8 @@ const LessonViewPage: React.FC = () => {
};
const handleAnswerSelect = async (questionId: string, optionKey: string) => {
// 🔧 ФИКС (01.10.2026): haptic_lesson_view — выбор варианта
haptic.selection();
setSelectedAnswers(prev => ({ ...prev, [questionId]: optionKey }));
// 🔧 ИСПРАВЛЕНО: обычный ответ — isFinalAnswer=true, hintUsed=false
await saveAnswer(questionId, optionKey, true, false);
@@ -159,6 +162,8 @@ const LessonViewPage: React.FC = () => {
setTextInputValue('');
startTimeRef.current = Date.now();
} else {
// 🔧 ФИКС (01.10.2026): haptic_lesson_view — завершение урока
haptic.heavy();
setIsCompleting(true);
// 🔧 ФИКС (25.09.2026): LESSON_NEXT_NO_RESULTS —
@@ -197,6 +202,8 @@ const LessonViewPage: React.FC = () => {
};
const handleBack = () => {
// 🔧 ФИКС (01.10.2026): haptic_lesson_view — вибрация возврата
haptic.light();
setShowHint(false);
if (currentQuestionIndex > 0) {
setCurrentQuestionIndex(prev => prev - 1);
@@ -554,6 +561,7 @@ const LessonViewPage: React.FC = () => {
return (
<button
key={option.option_key}
data-no-haptic="true"
onClick={() => handleAnswerSelect(currentQuestion.question.question_id, option.option_key)}
style={{
padding: '14px 16px',
@@ -650,6 +658,7 @@ const LessonViewPage: React.FC = () => {
</button>
<button
onClick={handleNext}
data-no-haptic="true"
disabled={!isCurrentAnswered || isCompleting}
style={{
flex: 1,
+10 -1
View File
@@ -2,6 +2,7 @@ import { useState, useEffect, useCallback } from 'react';
import { useNavigate } from 'react-router-dom';
import { useLanguage } from '../i18n/LanguageContext';
import { fonts, radius } from '../styles/theme';
import { haptic } from '../haptic';
import { getLearningLevels, getLearningTopics, getLearningProgress } from '../api';
interface LearningLevel {
@@ -152,6 +153,8 @@ const LessonsPage: React.FC = () => {
}}>
<button
onClick={() => {
// 🔧 ФИКС (01.10.2026): haptic_lessons_page — вибрация навигации
haptic.selection();
if (selectedLevel) {
setSelectedLevel(null);
} else {
@@ -193,7 +196,11 @@ const LessonsPage: React.FC = () => {
{levels.map((level, index) => (
<button
key={level.code}
onClick={() => handleLevelSelect(level.code)}
onClick={() => {
// 🔧 ФИКС (01.10.2026): haptic_lessons_page — вибрация выбора уровня
haptic.selection();
handleLevelSelect(level.code);
}}
style={{
padding: '18px',
borderRadius: radius.lg,
@@ -243,6 +250,8 @@ const LessonsPage: React.FC = () => {
key={topic.topic_id}
onClick={() => {
if (isUnlocked) {
// 🔧 ФИКС (01.10.2026): haptic_lessons_page — вибрация выбора темы
haptic.selection();
navigate(`/lessons/topic/${topic.topic_id}`);
}
}}
+9
View File
@@ -3,6 +3,7 @@ import { useNavigate, useLocation } from 'react-router-dom';
import { useLanguage } from '../i18n/LanguageContext';
import { useLocalized } from '../hooks/useLocalized';
import { fonts, radius } from '../styles/theme';
import { haptic } from '../haptic';
import { saveLearningAnswer, completeLearningSession } from '../api';
interface PracticeQuestion {
@@ -96,6 +97,8 @@ const PracticeViewPage: React.FC = () => {
};
const handleAnswerSelect = async (questionId: string, optionKey: string) => {
// 🔧 ФИКС (01.10.2026): haptic_practice_view — выбор варианта
haptic.selection();
setSelectedAnswers(prev => ({ ...prev, [questionId]: optionKey }));
// 🔧 ИСПРАВЛЕНО: обычный ответ — isFinalAnswer=true, hintUsed=false
await saveAnswer(questionId, optionKey, true, false);
@@ -138,6 +141,8 @@ const PracticeViewPage: React.FC = () => {
setTextInputValue('');
startTimeRef.current = Date.now();
} else {
// 🔧 ФИКС (01.10.2026): haptic_practice_view — завершение практики
haptic.heavy();
setIsCompleting(true);
// 🔧 ФИКС (24.09.2026): PRACTICE_DUPLICATE_SAVE —
@@ -160,6 +165,8 @@ const PracticeViewPage: React.FC = () => {
};
const handleBack = () => {
// 🔧 ФИКС (01.10.2026): haptic_practice_view — вибрация возврата
haptic.light();
setShowHint(false);
if (currentIndex > 0) {
setCurrentIndex(prev => prev - 1);
@@ -495,6 +502,7 @@ const PracticeViewPage: React.FC = () => {
return (
<button
key={option.option_key}
data-no-haptic="true"
onClick={() => handleAnswerSelect(currentQuestion.question.question_id, option.option_key)}
style={{
padding: '14px 16px',
@@ -587,6 +595,7 @@ const PracticeViewPage: React.FC = () => {
</button>
<button
onClick={handleNext}
data-no-haptic="true"
disabled={!isCurrentAnswered || isCompleting}
style={{
flex: 1,
+45 -22
View File
@@ -2,6 +2,7 @@ import { useState, useEffect, useCallback, useRef } from 'react';
import { useNavigate } from 'react-router-dom';
import { useLanguage } from '../i18n/LanguageContext';
import { fonts, radius } from '../styles/theme';
import { haptic } from '../haptic';
import { getNextPronunciationWord, trackPronunciationOpened, getTTS } from '../api';
import RulesModal from '../components/RulesModal';
import { useAchievements } from '../hooks/useAchievements';
@@ -53,6 +54,9 @@ const PronunciationPage: React.FC = () => {
});
const playWord = async (word: string) => {
// 🔧 ФИКС (01.10.2026): haptic_pronunciation — тап по слову
haptic.selection();
// Останавливаем предыдущее аудио
if (audioRef.current) {
audioRef.current.pause();
@@ -293,7 +297,12 @@ const PronunciationPage: React.FC = () => {
}}>
<div style={{ display: 'flex', gap: '8px', alignItems: 'center' }}>
<button
onClick={() => navigate('/menu')}
onClick={() => {
// 🔧 ФИКС (01.10.2026): haptic_pronunciation — навигация
haptic.light();
navigate('/menu');
}}
data-no-haptic="true"
style={{
...glass({
padding: '10px 18px',
@@ -312,7 +321,12 @@ const PronunciationPage: React.FC = () => {
← {t('back')}
</button>
<button
onClick={() => setShowRules(true)}
onClick={() => {
// 🔧 ФИКС (01.10.2026): haptic_pronunciation — открытие правил
haptic.light();
setShowRules(true);
}}
data-no-haptic="true"
style={{
...glass({
width: '40px',
@@ -374,25 +388,27 @@ const PronunciationPage: React.FC = () => {
{/* Карточка со словом */}
{currentWord && (
<div style={{
flex: 1,
...glass({
borderRadius: radius.lg,
padding: '32px',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
gap: '20px',
minHeight: '300px',
}),
border: `2px solid ${levelColor}30`,
animation: 'fadeInUp 0.3s ease 0.1s both',
cursor: 'pointer',
}}
onClick={() => playWord(currentWord.word_pl)}
onTouchStart={(e) => { e.currentTarget.style.transform = 'scale(0.98)'; }}
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
<div
data-no-haptic="true"
onClick={() => playWord(currentWord.word_pl)}
style={{
flex: 1,
...glass({
borderRadius: radius.lg,
padding: '32px',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
gap: '20px',
minHeight: '300px',
}),
border: `2px solid ${levelColor}30`,
animation: 'fadeInUp 0.3s ease 0.1s both',
cursor: 'pointer',
}}
onTouchStart={(e) => { e.currentTarget.style.transform = 'scale(0.98)'; }}
onTouchEnd={(e) => { e.currentTarget.style.transform = 'scale(1)'; }}
>
{/* Иконка динамика */}
<div style={{
@@ -460,7 +476,14 @@ const PronunciationPage: React.FC = () => {
{/* Кнопка Далее */}
<button
onClick={fetchWord}
data-no-haptic="true"
onClick={() => {
// 🔧 ФИКС (01.10.2026): haptic_pronunciation — следующее слово
// haptic ВНУТРИ onClick, а не в fetchWord,
// чтобы не было ложной вибрации при первом рендере.
haptic.light();
fetchWord();
}}
style={{
marginTop: '20px',
padding: '16px',
+23
View File
@@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom';
import { useLanguage } from '../i18n/LanguageContext';
import { useLocalized } from '../hooks/useLocalized';
import { fonts, radius } from '../styles/theme';
import { haptic } from '../haptic';
import {
teacherStart,
teacherResume,
@@ -352,6 +353,8 @@ const TeacherChatPage: React.FC = () => {
// ============ HANDLERS ============
const handleClearChat = () => {
// 🔧 ФИКС (01.10.2026): haptic_teacher_chat — очистка чата
haptic.medium();
setMessages([]);
setScreen({ kind: 'start' });
setSessionId(null);
@@ -378,6 +381,9 @@ const TeacherChatPage: React.FC = () => {
const handleStart = async () => {
if (isLoading) return;
// 🔧 ФИКС (01.10.2026): haptic_teacher_chat — старт урока
haptic.medium();
setShowMenuModal(false);
setIsLoading(true);
setSessionId(null);
@@ -462,6 +468,13 @@ const TeacherChatPage: React.FC = () => {
try {
const data = await teacherAnswer(sessionId, currentQuestionId, answer, timeTaken);
// 🔧 ФИКС (01.10.2026): haptic_teacher_chat — success/error на ответ
if (data.is_correct) {
haptic.success();
} else {
haptic.error();
}
let correctAnswerText = data.correct_answer || '';
if (!correctAnswerText) {
@@ -538,6 +551,9 @@ const TeacherChatPage: React.FC = () => {
// Переход к следующему вопросу (после ответа)
const handleNextQuestion = () => {
// 🔧 ФИКС (01.10.2026): haptic_teacher_chat — переход к следующему вопросу
haptic.light();
// Ищем последний вопрос в messages (последний добавленный)
const lastQuestion = [...messages].reverse().find(m => m.isQuestion);
@@ -613,6 +629,8 @@ const TeacherChatPage: React.FC = () => {
const handleSubmitAnswer = () => {
const text = inputValue.trim();
if (!text) return;
// 🔧 ФИКС (01.10.2026): haptic_teacher_chat — отправка свободного ответа
haptic.light();
handleAnswer(text);
};
@@ -861,6 +879,7 @@ const TeacherChatPage: React.FC = () => {
</p>
<button
onClick={handleStart}
data-no-haptic="true"
disabled={isLoading}
style={{
padding: '16px 32px', borderRadius: radius.lg, border: 'none',
@@ -1017,6 +1036,7 @@ const TeacherChatPage: React.FC = () => {
{currentQuestion.options.map((option) => (
<button
key={option.option_key}
data-no-haptic="true"
onClick={() => handleOptionClick(option)}
disabled={isLoading}
style={{
@@ -1059,6 +1079,7 @@ const TeacherChatPage: React.FC = () => {
/>
<button
onClick={handleSubmitAnswer}
data-no-haptic="true"
disabled={isLoading || !inputValue.trim()}
style={{
padding: '12px 18px', borderRadius: radius.md, border: 'none',
@@ -1130,6 +1151,7 @@ const TeacherChatPage: React.FC = () => {
{/* Кнопка "Следующий вопрос" */}
<button
onClick={handleNextQuestion}
data-no-haptic="true"
disabled={isLoading}
style={{
padding: '16px 24px', borderRadius: radius.lg, border: 'none',
@@ -1171,6 +1193,7 @@ const TeacherChatPage: React.FC = () => {
<button
onClick={handleStart}
data-no-haptic="true"
disabled={isLoading}
style={{
padding: '16px 32px', borderRadius: radius.lg, border: 'none',
+21 -2
View File
@@ -3,6 +3,7 @@ import { useNavigate, useParams } from 'react-router-dom';
import { useLanguage } from '../i18n/LanguageContext';
import { useLocalized } from '../hooks/useLocalized';
import { fonts, radius } from '../styles/theme';
import { haptic } from '../haptic';
import { getTopicTest, startLearningSession, saveLearningAnswer, completeLearningSession, teacherExamples, getLearningAnalytics, startWeakSkillsPractice, getTTS } from '../api';
interface QuestionOption {
@@ -151,6 +152,8 @@ const TestViewPage: React.FC = () => {
};
const handleAnswerSelect = async (questionId: string, optionKey: string) => {
// 🔧 ФИКС (01.10.2026): haptic_test_view — выбор варианта
haptic.selection();
setSelectedAnswers(prev => ({ ...prev, [questionId]: optionKey }));
// 🔧 ФИКС (23.09.2026): обычный ответ — isFinalAnswer=true, usedHint=false
await saveAnswer(questionId, optionKey, true, false);
@@ -174,6 +177,8 @@ const TestViewPage: React.FC = () => {
setTextInputValue('');
startTimeRef.current = Date.now();
} else {
// 🔧 ФИКС (01.10.2026): haptic_test_view — завершение теста
haptic.heavy();
setIsCompleting(true);
// 🔧 ФИКС (24.09.2026): TESTVIEW_DUPLICATE_SAVE —
@@ -196,6 +201,8 @@ const TestViewPage: React.FC = () => {
};
const handleBack = () => {
// 🔧 ФИКС (01.10.2026): haptic_test_view — вибрация возврата
haptic.light();
if (currentIndex > 0) {
setCurrentIndex(prev => prev - 1);
setTextInputValue('');
@@ -410,7 +417,12 @@ const TestViewPage: React.FC = () => {
{/* 🔧 НОВОЕ: Кнопки "Дай примеры" и "Потренировать слабые темы" */}
<div style={{ marginTop: '20px', width: '100%', maxWidth: '300px', display: 'flex', flexDirection: 'column', gap: '10px' }}>
<button
onClick={handleLoadExamples}
onClick={() => {
// 🔧 ФИКС (01.10.2026): haptic_test_view — вибрация загрузки примеров
haptic.medium();
handleLoadExamples();
}}
data-no-haptic="true"
disabled={isLoadingExamples}
style={{
width: '100%',
@@ -436,7 +448,12 @@ const TestViewPage: React.FC = () => {
💡 {t('testExamplesButton')}
</button>
<button
onClick={handleStartPractice}
onClick={() => {
// 🔧 ФИКС (01.10.2026): haptic_test_view — вибрация старта практики
haptic.medium();
handleStartPractice();
}}
data-no-haptic="true"
disabled={isStartingPractice}
style={{
width: '100%',
@@ -717,6 +734,7 @@ const TestViewPage: React.FC = () => {
return (
<button
key={option.option_key}
data-no-haptic="true"
onClick={() => handleAnswerSelect(currentQuestion.question.question_id, option.option_key)}
style={{
padding: '14px 16px',
@@ -786,6 +804,7 @@ const TestViewPage: React.FC = () => {
</button>
<button
onClick={handleNext}
data-no-haptic="true"
disabled={!isCurrentAnswered || isCompleting}
style={{
flex: 1,