🌊 Волна 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:
2026-09-24 20:00:59 +03:00
parent 87f482861b
commit 5c27b98f4b
8 changed files with 221 additions and 56 deletions
+106 -7
View File
@@ -232,6 +232,17 @@ const fetchAPI = async (endpoint: string, options: RequestInit = {}) => {
throw new Error(`API Error: ${res.status} - ${errorText}`);
}
// 🔧 ФИКС (24.09.2026): FETCH_JSON_NO_CONTENT_TYPE_CHECK —
// проверяем content-type перед парсингом JSON, чтобы не получить
// неинформативный 'Unexpected token < in JSON' (captive portal, CF challenge).
const contentType = res.headers.get('content-type') || '';
if (!contentType.includes('application/json')) {
const text = await res.text();
throw new Error(
`API Error: expected JSON, got ${contentType}. Body: ${text.slice(0, 200)}`
);
}
const data = await res.json();
return data;
};
@@ -409,10 +420,39 @@ export const saveAnalyticsToHistory = (message: string): Promise<{ status: strin
body: JSON.stringify({ message }),
});
export const getPersonalStats = (): Promise<any> =>
// 🔧 ФИКС (24.09.2026): ANY_TYPES_PERSONAL_STATS —
// типизируем ответ. Если поля изменятся, TS подсветит.
export interface PersonalStatsResponse {
current_level: string;
total_score: number;
achievements: number;
words_guessed: number;
bubble_levels: number;
completed_topics: number;
level_progress: Record<string, {
wordsearch_percent: number;
wordsearch_completed: number;
wordsearch_total: number;
sentence_percent: number;
sentence_completed: number;
sentence_total: number;
total_score: number;
}>;
}
// 🔧 ФИКС (24.09.2026): ANY_TYPES_ADMIN_STATS_ASSISTANT
export interface AdminStatsResponse {
total_users: number;
new_today: number;
online_now: number;
language_counts: Record<string, number>;
level_counts: Record<string, number>;
}
export const getPersonalStats = (): Promise<PersonalStatsResponse> =>
fetchAPI('/assistant/stats/personal');
export const getAdminStatsFromAssistant = (): Promise<any> =>
export const getAdminStatsFromAssistant = (): Promise<AdminStatsResponse> =>
fetchAPI('/assistant/stats/admin');
// ============ Уроки (Learning) ============
@@ -1150,12 +1190,71 @@ export const getLessonTopics = (level: string): Promise<{ level: string; topics:
export const getLessonTopic = (topicId: string): Promise<ContentTopicDetail> =>
fetchAPI(`/admin/content/lessons/topic/${encodeURIComponent(topicId)}`);
// 🔧 ФИКС (24.09.2026): ANY_TYPES_LESSON_FULL —
// типизируем lesson/examples/questions для WYSIWYG.
export interface LessonFullExample {
id?: number;
order_number?: number;
text_pl: string;
text_ru: string;
text_uk: string;
text_en: string;
audio_url?: string | null;
}
export interface LessonFullOption {
option_key: string;
text_pl: string;
text_ru: string;
text_uk: string;
text_en: string;
is_correct: boolean;
wrong_because: string | null;
wrong_because_text?: string;
}
export interface LessonFullQuestion {
question_id: string;
context_type: string;
question_type: string;
skill_tag: string;
difficulty: number;
prompt_pl: string;
prompt_ru: string;
prompt_uk: string;
prompt_en: string;
correct_answer: string;
hint_type: string | null;
hint_value: string | null;
options_language: string;
options: LessonFullOption[];
}
export interface LessonFullResponse {
lesson: {
lesson_id: string;
topic_id: string;
order_number: number;
skill_tag: string;
title_pl: string;
title_ru: string;
title_uk: string;
title_en: string;
objective_pl: string;
objective_ru: string;
objective_uk: string;
objective_en: string;
explanation_pl: string;
explanation_ru: string;
explanation_uk: string;
explanation_en: string;
};
examples: LessonFullExample[];
questions: LessonFullQuestion[];
}
// Урок целиком (для WYSIWYG)
export const getLessonFull = (lessonId: string): Promise<{
lesson: any;
examples: any[];
questions: any[];
}> =>
export const getLessonFull = (lessonId: string): Promise<LessonFullResponse> =>
fetchAPI(`/admin/content/lessons/lesson/${encodeURIComponent(lessonId)}`);
// Сохранить урок