🌊 Волна 16: frontend #6 — юзабилити + типы (15 багов)
Юзабилити: - BUBBLE_MESSAGE_OVERLAP: message/errorMessage взаимоисключение (BubbleWordsPage.tsx) - REGISTER_FAILURE_NO_RETRY_IN_SESSION: retry с backoff (App.tsx) - TESTVIEW_DUPLICATE_SAVE: убран дубль saveAnswer (TestViewPage.tsx) - TEACHER_TOAST_NO_CLEANUP: clearTimeout (TeacherChatPage.tsx) - TESTVIEW_TOAST_NO_CLEANUP: clearTimeout (TestViewPage.tsx) Производительность: - MENU_LEADERBOARD_HEAVY_FETCH: limit 100→50 (MenuPage.tsx) - FLASHCARDS_RETRACK_ON_ACHIEVEMENT: одноразовый трекинг (FlashcardsPage.tsx) - TEACHER_HISTORY_SAVE_EVERY_MESSAGE: debounce 500мс (TeacherChatPage.tsx) - LEADERBOARD_GETUSERID_EVERY_RENDER: useState initializer (LeaderboardPage.tsx) Типы: - ANY_TYPES_PERSONAL_STATS + ADMIN_STATS: интерфейсы (api.ts) - ANY_TYPES_LESSON_FULL: LessonFullResponse (api.ts) Качество: - SILENT_ERROR_SWALLOWING_APP: console.warn (App.tsx) - STALE_CLOSURE_NAVIGATE_SETLANG: useRef для navigate/setLang (App.tsx) - FETCH_JSON_NO_CONTENT_TYPE_CHECK: проверка content-type (api.ts) Пропущено осознанно: - INIT_DATA_IN_URL_DELETE_FEED (Cloudflare preflight) Аудит v4: Issue #6, frontend 15/16 задач
This commit is contained in:
@@ -148,6 +148,10 @@ const BubbleWordsPage: React.FC = () => {
|
||||
|
||||
const showMessage = (msg: string) => {
|
||||
if (!isMountedRef.current) return;
|
||||
// 🔧 ФИКС (24.09.2026): BUBBLE_MESSAGE_OVERLAP — скрываем errorMessage
|
||||
// при показе message (взаимоисключение).
|
||||
setErrorMessage(null);
|
||||
if (errorTimeoutRef.current) clearTimeout(errorTimeoutRef.current);
|
||||
setMessage(msg);
|
||||
if (messageTimeoutRef.current) clearTimeout(messageTimeoutRef.current);
|
||||
messageTimeoutRef.current = setTimeout(() => {
|
||||
@@ -159,6 +163,10 @@ const BubbleWordsPage: React.FC = () => {
|
||||
// с автоскрытием через 2 секунды (по аналогии с showMessage).
|
||||
const showError = (msg: string) => {
|
||||
if (!isMountedRef.current) return;
|
||||
// 🔧 ФИКС (24.09.2026): BUBBLE_MESSAGE_OVERLAP — скрываем message
|
||||
// при показе errorMessage (взаимоисключение).
|
||||
setMessage(null);
|
||||
if (messageTimeoutRef.current) clearTimeout(messageTimeoutRef.current);
|
||||
setErrorMessage(msg);
|
||||
if (errorTimeoutRef.current) clearTimeout(errorTimeoutRef.current);
|
||||
errorTimeoutRef.current = setTimeout(() => {
|
||||
@@ -496,7 +504,9 @@ const BubbleWordsPage: React.FC = () => {
|
||||
{errorMessage && (
|
||||
<div style={{
|
||||
position: 'absolute',
|
||||
top: '60px',
|
||||
// 🔧 ФИКС (24.09.2026): BUBBLE_MESSAGE_OVERLAP —
|
||||
// errorMessage опускаем на 100px, чтобы не перекрывалась с message (60px).
|
||||
top: '100px',
|
||||
left: '50%',
|
||||
transform: 'translateX(-50%)',
|
||||
padding: '10px 20px',
|
||||
|
||||
@@ -146,12 +146,30 @@ const FlashcardsPage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 🔧 ФИКС (24.09.2026): FLASHCARDS_RETRACK_ON_ACHIEVEMENT —
|
||||
// вынесли трекинг в отдельный useEffect с [] (одноразовый),
|
||||
// чтобы showAchievement не вызывал повторный трекинг при смене identity.
|
||||
useEffect(() => {
|
||||
window.scrollTo(0, 0);
|
||||
|
||||
isMountedRef.current = true;
|
||||
return () => {
|
||||
isMountedRef.current = false;
|
||||
if (audioRef.current) {
|
||||
audioRef.current.pause();
|
||||
audioRef.current = null;
|
||||
}
|
||||
if (audioUrlRef.current) {
|
||||
try { URL.revokeObjectURL(audioUrlRef.current); } catch { /* ignore */ }
|
||||
audioUrlRef.current = null;
|
||||
}
|
||||
if ('speechSynthesis' in window) {
|
||||
window.speechSynthesis.cancel();
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 🔧 ИСПРАВЛЕНО: Трекинг только для Алфавита (активная вкладка по умолчанию)
|
||||
// Одноразовый трекинг при монтировании
|
||||
useEffect(() => {
|
||||
trackAlphabetOpened()
|
||||
.then((data: any) => {
|
||||
if (data?.new_achievements && data.new_achievements.length > 0) {
|
||||
@@ -165,23 +183,8 @@ const FlashcardsPage: React.FC = () => {
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
return () => {
|
||||
isMountedRef.current = false;
|
||||
if (audioRef.current) {
|
||||
audioRef.current.pause();
|
||||
audioRef.current = null;
|
||||
}
|
||||
// 🔧 ФИКС (24.09.2026): URL_LEAK_FLASHCARDS — освобождаем URL при unmount
|
||||
if (audioUrlRef.current) {
|
||||
try { URL.revokeObjectURL(audioUrlRef.current); } catch { /* ignore */ }
|
||||
audioUrlRef.current = null;
|
||||
}
|
||||
if ('speechSynthesis' in window) {
|
||||
window.speechSynthesis.cancel();
|
||||
}
|
||||
};
|
||||
}, [showAchievement]);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
// 🔧 ИСПРАВЛЕНО: switchTab теперь сбрасывает window scroll
|
||||
const switchTab = (tab: TabType) => {
|
||||
|
||||
@@ -127,7 +127,9 @@ const LeaderboardPage: React.FC = () => {
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [selectedAchievement, setSelectedAchievement] = useState<UserAchievement | null>(null);
|
||||
const [showAchievements, setShowAchievements] = useState(false);
|
||||
const currentUserId = getUserId();
|
||||
// 🔧 ФИКС (24.09.2026): LEADERBOARD_GETUSERID_EVERY_RENDER —
|
||||
// getUserId() один раз через useState (initializer), не на каждый рендер.
|
||||
const [currentUserId] = useState<number | null>(() => getUserId());
|
||||
|
||||
const brandColor = '#2ECC71';
|
||||
const palette = {
|
||||
|
||||
@@ -168,7 +168,10 @@ const MenuPage: React.FC = () => {
|
||||
setTotalScore(0);
|
||||
});
|
||||
|
||||
getLeaderboard(100)
|
||||
// 🔧 ФИКС (24.09.2026): MENU_LEADERBOARD_HEAVY_FETCH —
|
||||
// вместо 100 записей грузим 50 (в 2 раза меньше трафика).
|
||||
// TODO: вынести в отдельный endpoint /leaderboard/my-rank.
|
||||
getLeaderboard(50)
|
||||
.then((data) => {
|
||||
const leaderboard = data.leaderboard || [];
|
||||
const myEntry = leaderboard.find((entry: any) =>
|
||||
|
||||
@@ -110,6 +110,11 @@ const TeacherChatPage: React.FC = () => {
|
||||
// на КАЖДЫЙ рендер — O(n) при длинном чате. Теперь useRef(0),
|
||||
// а актуальное значение ставится один раз при загрузке истории (в useEffect).
|
||||
const idRef = useRef(0);
|
||||
// 🔧 ФИКС (24.09.2026): TEACHER_TOAST_NO_CLEANUP —
|
||||
// храним таймер для очистки.
|
||||
const toastTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
// 🔧 ФИКС (24.09.2026): TEACHER_HISTORY_SAVE_EVERY_MESSAGE
|
||||
const historySaveTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const startTimeRef = useRef<number>(Date.now());
|
||||
|
||||
const brandColor = '#2ECC71';
|
||||
@@ -133,9 +138,11 @@ const TeacherChatPage: React.FC = () => {
|
||||
};
|
||||
|
||||
// 🔧 ФИКС (23.09.2026): ALERT_IN_TELEGRAM_MINIAPP — helper для toast вместо alert()
|
||||
// 🔧 ФИКС (24.09.2026): TEACHER_TOAST_NO_CLEANUP — сохраняем таймер.
|
||||
const showToast = (msg: string) => {
|
||||
setToastMessage(msg);
|
||||
setTimeout(() => {
|
||||
if (toastTimeoutRef.current) clearTimeout(toastTimeoutRef.current);
|
||||
toastTimeoutRef.current = setTimeout(() => {
|
||||
setToastMessage(null);
|
||||
}, 2500);
|
||||
};
|
||||
@@ -240,15 +247,23 @@ const TeacherChatPage: React.FC = () => {
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
// 🔧 ФИКС (24.09.2026): TEACHER_HISTORY_SAVE_EVERY_MESSAGE —
|
||||
// дебаунсим сохранение истории на сервер (500мс), чтобы не долбить
|
||||
// бэк при каждом новом сообщении.
|
||||
useEffect(() => {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(messages));
|
||||
if (messages.length > 0) {
|
||||
saveTeacherHistory(messages).catch(() => {});
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
if (messages.length === 0) return;
|
||||
if (historySaveTimeoutRef.current) clearTimeout(historySaveTimeoutRef.current);
|
||||
historySaveTimeoutRef.current = setTimeout(() => {
|
||||
saveTeacherHistory(messages).catch(() => {});
|
||||
}, 500);
|
||||
return () => {
|
||||
if (historySaveTimeoutRef.current) clearTimeout(historySaveTimeoutRef.current);
|
||||
};
|
||||
}, [messages]);
|
||||
|
||||
const extractPolishText = (text: string): string => {
|
||||
@@ -403,6 +418,11 @@ const TeacherChatPage: React.FC = () => {
|
||||
try { URL.revokeObjectURL(audioUrlRef.current); } catch { /* ignore */ }
|
||||
audioUrlRef.current = null;
|
||||
}
|
||||
// 🔧 ФИКС (24.09.2026): TEACHER_TOAST_NO_CLEANUP
|
||||
if (toastTimeoutRef.current) {
|
||||
clearTimeout(toastTimeoutRef.current);
|
||||
toastTimeoutRef.current = null;
|
||||
}
|
||||
if ('speechSynthesis' in window) {
|
||||
window.speechSynthesis.cancel();
|
||||
}
|
||||
|
||||
+18
-17
@@ -53,6 +53,9 @@ const TestViewPage: React.FC = () => {
|
||||
const [isStartingPractice, setIsStartingPractice] = useState(false);
|
||||
// 🔧 ФИКС (24.09.2026): ALERT_IN_TELEGRAM_MINIAPP — toast вместо alert().
|
||||
const [toastMessage, setToastMessage] = useState<string | null>(null);
|
||||
// 🔧 ФИКС (24.09.2026): TESTVIEW_TOAST_NO_CLEANUP —
|
||||
// храним таймер для очистки.
|
||||
const toastTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const audioRef = useRef<HTMLAudioElement | null>(null);
|
||||
// 🔧 ФИКС (24.09.2026): URL_LEAK_TESTVIEW — храним URL для revoke.
|
||||
const audioUrlRef = useRef<string | null>(null);
|
||||
@@ -73,9 +76,11 @@ const TestViewPage: React.FC = () => {
|
||||
});
|
||||
|
||||
// 🔧 ФИКС (24.09.2026): ALERT_IN_TELEGRAM_MINIAPP — helper для toast.
|
||||
// 🔧 ФИКС (24.09.2026): TESTVIEW_TOAST_NO_CLEANUP — сохраняем таймер.
|
||||
const showToast = (msg: string) => {
|
||||
setToastMessage(msg);
|
||||
setTimeout(() => setToastMessage(null), 2500);
|
||||
if (toastTimeoutRef.current) clearTimeout(toastTimeoutRef.current);
|
||||
toastTimeoutRef.current = setTimeout(() => setToastMessage(null), 2500);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -112,6 +117,11 @@ const TestViewPage: React.FC = () => {
|
||||
try { URL.revokeObjectURL(audioUrlRef.current); } catch { /* ignore */ }
|
||||
audioUrlRef.current = null;
|
||||
}
|
||||
// 🔧 ФИКС (24.09.2026): TESTVIEW_TOAST_NO_CLEANUP
|
||||
if (toastTimeoutRef.current) {
|
||||
clearTimeout(toastTimeoutRef.current);
|
||||
toastTimeoutRef.current = null;
|
||||
}
|
||||
if ('speechSynthesis' in window) {
|
||||
window.speechSynthesis.cancel();
|
||||
}
|
||||
@@ -165,24 +175,15 @@ const TestViewPage: React.FC = () => {
|
||||
startTimeRef.current = Date.now();
|
||||
} else {
|
||||
setIsCompleting(true);
|
||||
|
||||
// Сохраняем ответ последнего вопроса
|
||||
const currentQ = questions[currentIndex];
|
||||
const answer = selectedAnswers[currentQ.question.question_id];
|
||||
|
||||
if (answer && sessionId) {
|
||||
const timeTaken = Date.now() - startTimeRef.current;
|
||||
try {
|
||||
// 🔧 ФИКС (23.09.2026): TESTVIEW_SAVEANSWER_MISSING_PARAMS
|
||||
await saveLearningAnswer(sessionId, currentQ.question.question_id, answer, timeTaken, true, false);
|
||||
} catch (e) {
|
||||
console.error('Error saving final answer:', e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 🔧 ФИКС (24.09.2026): TESTVIEW_DUPLICATE_SAVE —
|
||||
// ответ последнего вопроса уже сохранён в handleAnswerSelect /
|
||||
// handleTextInputBlur. Повторно НЕ сохраняем — убираем дубль.
|
||||
// (как в PracticeViewPage)
|
||||
|
||||
// Небольшая задержка для сохранения
|
||||
await new Promise(resolve => setTimeout(resolve, 300));
|
||||
|
||||
|
||||
if (sessionId) {
|
||||
try {
|
||||
const result = await completeLearningSession(sessionId);
|
||||
|
||||
Reference in New Issue
Block a user