🌊 Волна 20: frontend — Escape + backdrop close (10 фиксов)
Escape (7 модалок): - LessonEditorModal: Escape с блокировкой при saving - OnboardingModal: Escape → onClose - PronunciationModal: Escape → onClose - RulesModal: Escape + хук до early return (нарушение правил хуков) - SupportChatModal: Escape с блокировкой при showDeleteConfirm - TeacherMenuModal: Escape → handleClose - TypingModal: Escape → onClose Escape + backdrop (2 редактора): - TextsEditor: Escape + backdrop + Escape для вложенных модалок (TextEditModal, TextCreateModal с блокировкой при saving) - WordsEditor: то же для WordEditModal, WordCreateModal Игра: - WordSearchPage: WORDSEARCH_HINT_WASTED_NO_PATH — подсказка списывается только после успешной подсветки, ищет слово С путём (а не первое ненайденное) Снято с аудита: - useAchievements уже стабилен через useCallback([]) — баги WORDSEARCH_LEVEL_REFETCH_ON_RESET, SENTENCE_REFETCH_ON_RESET, PRONUNCIATION_REFETCH_ON_ACHIEVEMENT, BUBBLE_EFFECT_SHOWACHIEVEMENT_DEP — закрыты фиксом 24.09 Аудит v7: 10 из 18 закрыто
This commit is contained in:
@@ -174,6 +174,17 @@ const LessonEditorModal: React.FC<LessonEditorModalProps> = ({
|
||||
.finally(() => setLoading(false));
|
||||
}, [isOpen, lessonId]);
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): lesson_editor_no_escape —
|
||||
// обработчик Escape. Не срабатывает во время сохранения (saving).
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && !saving) onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [isOpen, onClose, saving]);
|
||||
|
||||
// ============ Примеры: add/remove ============
|
||||
const addExample = () => {
|
||||
setExamples(prev => [
|
||||
|
||||
@@ -49,6 +49,17 @@ const OnboardingModal: React.FC<OnboardingModalProps> = ({ isOpen, onClose, onCo
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): onboarding_no_escape —
|
||||
// обработчик Escape. Закрывает через onClose (как клик по фону).
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [isOpen, onClose]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
const isLastStep = step === steps.length - 1;
|
||||
|
||||
@@ -112,6 +112,17 @@ const PronunciationModal: React.FC<PronunciationModalProps> = ({ isOpen, onClose
|
||||
};
|
||||
}, [isOpen, fetchWord]);
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): pronunciation_no_escape —
|
||||
// обработчик Escape. Закрывает модалку и останавливает аудио.
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [isOpen, onClose]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
const levelColor = currentWord?.level ? levelColors[currentWord.level] || brandColor : brandColor;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useEffect } from 'react';
|
||||
import { colors, radius } from '../styles/theme';
|
||||
|
||||
interface RulesModalProps {
|
||||
@@ -13,6 +14,17 @@ const RulesModal: React.FC<RulesModalProps> = ({
|
||||
title,
|
||||
content,
|
||||
}) => {
|
||||
// 🔧 ФИКС (25.09.2026): rules_no_escape —
|
||||
// обработчик Escape. Hooks должны идти ДО раннего return.
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [isOpen, onClose]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
return (
|
||||
|
||||
@@ -171,6 +171,21 @@ const SupportChatModal: React.FC<SupportChatModalProps> = ({ isOpen, onClose, is
|
||||
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||
}, [messages]);
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): support_chat_no_escape —
|
||||
// обработчик Escape. Модалка — это SupportChatModal, поэтому
|
||||
// слушатель должен быть здесь, а не в MenuPage.
|
||||
// НЕ закрываем при открытой delete-подтверждалке.
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && !showDeleteConfirm) {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [isOpen, onClose, showDeleteConfirm]);
|
||||
|
||||
const handleSend = async () => {
|
||||
const text = inputValue.trim();
|
||||
if (!text || isLoading) return;
|
||||
|
||||
@@ -161,6 +161,18 @@ const TeacherMenuModal: React.FC<TeacherMenuModalProps> = ({
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): teacher_menu_no_escape —
|
||||
// обработчик Escape. Закрывает меню и сбрасывает состояние через handleClose.
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') handleClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isOpen]);
|
||||
|
||||
const handleOpenLetter = (index: number) => {
|
||||
setSelectedLetter(index);
|
||||
scrollToTop();
|
||||
|
||||
@@ -65,6 +65,20 @@ const TextsEditor: React.FC<TextsEditorProps> = ({ isOpen, onClose }) => {
|
||||
.finally(() => setLoading(false));
|
||||
}, [selectedLevel, debouncedSearch]);
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): texts_editor_no_backdrop_close —
|
||||
// Escape для основного редактора. Не срабатывает, если
|
||||
// открыта вложенная модалка (edit / create) — она сама
|
||||
// обработает Escape.
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
if (editingText || isCreating) return;
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [isOpen, onClose, editingText, isCreating]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
const textColor = '#1A1A2E';
|
||||
@@ -89,6 +103,7 @@ const TextsEditor: React.FC<TextsEditorProps> = ({ isOpen, onClose }) => {
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
padding: '20px',
|
||||
}}
|
||||
onClick={(e) => { if (e.target === e.currentTarget) onClose(); }}
|
||||
>
|
||||
<div
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
@@ -320,6 +335,16 @@ const TextEditModal: React.FC<{
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): texts_editor_no_backdrop_close —
|
||||
// Escape для вложенной модалки редактирования.
|
||||
useEffect(() => {
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && !saving) onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [onClose, saving]);
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!sentencePl.trim()) {
|
||||
setError('Польский текст обязателен');
|
||||
@@ -452,6 +477,16 @@ const TextCreateModal: React.FC<{
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): texts_editor_no_backdrop_close —
|
||||
// Escape для вложенной модалки создания.
|
||||
useEffect(() => {
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && !saving) onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [onClose, saving]);
|
||||
|
||||
// Живой предпросмотр: "PL, EN, RU, UK"
|
||||
const parts = input.split(',').map((s) => s.trim());
|
||||
const preview = {
|
||||
|
||||
@@ -114,6 +114,17 @@ const TypingModal: React.FC<TypingModalProps> = ({ isOpen, onClose }) => {
|
||||
};
|
||||
}, [isOpen, fetchSentence]);
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): typing_modal_no_escape —
|
||||
// обработчик Escape. Не закрываем, пока идёт проверка ответа.
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [isOpen, onClose]);
|
||||
|
||||
const handleCheck = async () => {
|
||||
if (!sentence || !inputValue.trim()) return;
|
||||
|
||||
|
||||
@@ -65,6 +65,19 @@ const WordsEditor: React.FC<WordsEditorProps> = ({ isOpen, onClose }) => {
|
||||
.finally(() => setLoading(false));
|
||||
}, [selectedLevel, debouncedSearch]);
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): words_editor_no_backdrop_close —
|
||||
// Escape для основного редактора. Не срабатывает, если
|
||||
// открыта вложенная модалка (edit / create).
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
if (editingWord || isCreating) return;
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [isOpen, onClose, editingWord, isCreating]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
const textColor = '#1A1A2E';
|
||||
@@ -89,6 +102,7 @@ const WordsEditor: React.FC<WordsEditorProps> = ({ isOpen, onClose }) => {
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
padding: '20px',
|
||||
}}
|
||||
onClick={(e) => { if (e.target === e.currentTarget) onClose(); }}
|
||||
>
|
||||
<div
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
@@ -323,6 +337,16 @@ const WordEditModal: React.FC<{
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): words_editor_no_backdrop_close —
|
||||
// Escape для вложенной модалки редактирования.
|
||||
useEffect(() => {
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && !saving) onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [onClose, saving]);
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!wordPl.trim()) {
|
||||
setError('Польское слово обязательно');
|
||||
@@ -453,6 +477,16 @@ const WordCreateModal: React.FC<{
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): words_editor_no_backdrop_close —
|
||||
// Escape для вложенной модалки создания.
|
||||
useEffect(() => {
|
||||
const handleKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && !saving) onClose();
|
||||
};
|
||||
window.addEventListener('keydown', handleKey);
|
||||
return () => window.removeEventListener('keydown', handleKey);
|
||||
}, [onClose, saving]);
|
||||
|
||||
// Живой предпросмотр: парсим "PL, EN, RU, UK"
|
||||
const parts = input.split(',').map((s) => s.trim());
|
||||
const preview = {
|
||||
|
||||
@@ -344,23 +344,35 @@ const WordSearchPage: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// 🔧 ФИКС (25.09.2026): WORDSEARCH_HINT_WASTED_NO_PATH —
|
||||
// сначала ищем слово с путём, и только если нашли — списываем подсказку.
|
||||
const paths = level.word_paths || {};
|
||||
const notFoundWithPath = words.find(w =>
|
||||
!foundWordsRef.current.includes(w.word_pl) &&
|
||||
paths[w.word_pl] &&
|
||||
paths[w.word_pl][0]
|
||||
);
|
||||
|
||||
if (!notFoundWithPath) {
|
||||
// Нет ни одного ненайденного слова с путём — подсказка бесполезна,
|
||||
// счётчик НЕ списываем.
|
||||
showError('⚠️ ' + (t('noMoreFirstLetterHints') || 'No hints available'));
|
||||
return;
|
||||
}
|
||||
|
||||
const path = paths[notFoundWithPath.word_pl];
|
||||
setFirstLetterCell(path[0] as [number, number]);
|
||||
|
||||
// Списываем подсказку только после успешной установки подсветки.
|
||||
const newHintsUsed = firstLetterHintsUsedRef.current + 1;
|
||||
firstLetterHintsUsedRef.current = newHintsUsed;
|
||||
setFirstLetterHintsUsed(newHintsUsed);
|
||||
|
||||
const notFound = words.find(w => !foundWordsRef.current.includes(w.word_pl));
|
||||
if (notFound) {
|
||||
const paths = level.word_paths || {};
|
||||
const path = paths[notFound.word_pl];
|
||||
if (path && path[0]) {
|
||||
setFirstLetterCell(path[0] as [number, number]);
|
||||
setTimeout(() => {
|
||||
if (isMountedRef.current) {
|
||||
setFirstLetterCell(null);
|
||||
}
|
||||
}, 2000);
|
||||
setTimeout(() => {
|
||||
if (isMountedRef.current) {
|
||||
setFirstLetterCell(null);
|
||||
}
|
||||
}
|
||||
}, 2000);
|
||||
}, [level, words, t]);
|
||||
|
||||
const handleShowWords = useCallback(() => {
|
||||
|
||||
Reference in New Issue
Block a user