From 5b0a1a5deccf828e54a146f2305386888b635495 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Fri, 25 Sep 2026 18:37:46 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=8A=20=D0=92=D0=BE=D0=BB=D0=BD=D0=B0?= =?UTF-8?q?=2020:=20frontend=20=E2=80=94=20Escape=20+=20backdrop=20close?= =?UTF-8?q?=20(10=20=D1=84=D0=B8=D0=BA=D1=81=D0=BE=D0=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 закрыто --- src/components/LessonEditorModal.tsx | 11 ++++++++ src/components/OnboardingModal.tsx | 11 ++++++++ src/components/PronunciationModal.tsx | 11 ++++++++ src/components/RulesModal.tsx | 12 +++++++++ src/components/SupportChatModal.tsx | 15 +++++++++++ src/components/TeacherMenuModal.tsx | 12 +++++++++ src/components/TextsEditor.tsx | 35 ++++++++++++++++++++++++++ src/components/TypingModal.tsx | 11 ++++++++ src/components/WordsEditor.tsx | 34 +++++++++++++++++++++++++ src/pages/WordSearchPage.tsx | 36 ++++++++++++++++++--------- 10 files changed, 176 insertions(+), 12 deletions(-) diff --git a/src/components/LessonEditorModal.tsx b/src/components/LessonEditorModal.tsx index d411394..16a0cfc 100644 --- a/src/components/LessonEditorModal.tsx +++ b/src/components/LessonEditorModal.tsx @@ -174,6 +174,17 @@ const LessonEditorModal: React.FC = ({ .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 => [ diff --git a/src/components/OnboardingModal.tsx b/src/components/OnboardingModal.tsx index 37cb944..be41394 100644 --- a/src/components/OnboardingModal.tsx +++ b/src/components/OnboardingModal.tsx @@ -49,6 +49,17 @@ const OnboardingModal: React.FC = ({ 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; diff --git a/src/components/PronunciationModal.tsx b/src/components/PronunciationModal.tsx index 69b8b8d..e2a79a9 100644 --- a/src/components/PronunciationModal.tsx +++ b/src/components/PronunciationModal.tsx @@ -112,6 +112,17 @@ const PronunciationModal: React.FC = ({ 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; diff --git a/src/components/RulesModal.tsx b/src/components/RulesModal.tsx index b3b8488..747ab5c 100644 --- a/src/components/RulesModal.tsx +++ b/src/components/RulesModal.tsx @@ -1,3 +1,4 @@ +import { useEffect } from 'react'; import { colors, radius } from '../styles/theme'; interface RulesModalProps { @@ -13,6 +14,17 @@ const RulesModal: React.FC = ({ 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 ( diff --git a/src/components/SupportChatModal.tsx b/src/components/SupportChatModal.tsx index 6a9d0b6..645fdf2 100644 --- a/src/components/SupportChatModal.tsx +++ b/src/components/SupportChatModal.tsx @@ -171,6 +171,21 @@ const SupportChatModal: React.FC = ({ 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; diff --git a/src/components/TeacherMenuModal.tsx b/src/components/TeacherMenuModal.tsx index 69bed77..2838e90 100644 --- a/src/components/TeacherMenuModal.tsx +++ b/src/components/TeacherMenuModal.tsx @@ -161,6 +161,18 @@ const TeacherMenuModal: React.FC = ({ }; }, []); + // 🔧 ФИКС (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(); diff --git a/src/components/TextsEditor.tsx b/src/components/TextsEditor.tsx index 9a44b43..1d89b63 100644 --- a/src/components/TextsEditor.tsx +++ b/src/components/TextsEditor.tsx @@ -65,6 +65,20 @@ const TextsEditor: React.FC = ({ 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 = ({ isOpen, onClose }) => { display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '20px', }} + onClick={(e) => { if (e.target === e.currentTarget) onClose(); }} >
e.stopPropagation()} @@ -320,6 +335,16 @@ const TextEditModal: React.FC<{ const [saving, setSaving] = useState(false); const [error, setError] = useState(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(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 = { diff --git a/src/components/TypingModal.tsx b/src/components/TypingModal.tsx index f637125..b7ab5fb 100644 --- a/src/components/TypingModal.tsx +++ b/src/components/TypingModal.tsx @@ -114,6 +114,17 @@ const TypingModal: React.FC = ({ 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; diff --git a/src/components/WordsEditor.tsx b/src/components/WordsEditor.tsx index eed25f4..1d84ef5 100644 --- a/src/components/WordsEditor.tsx +++ b/src/components/WordsEditor.tsx @@ -65,6 +65,19 @@ const WordsEditor: React.FC = ({ 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 = ({ isOpen, onClose }) => { display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '20px', }} + onClick={(e) => { if (e.target === e.currentTarget) onClose(); }} >
e.stopPropagation()} @@ -323,6 +337,16 @@ const WordEditModal: React.FC<{ const [saving, setSaving] = useState(false); const [error, setError] = useState(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(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 = { diff --git a/src/pages/WordSearchPage.tsx b/src/pages/WordSearchPage.tsx index f5edfbc..b614380 100644 --- a/src/pages/WordSearchPage.tsx +++ b/src/pages/WordSearchPage.tsx @@ -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(() => {