fix(frontend): export ui object, harmonize API signatures, and clean view switcher

This commit is contained in:
Antigravity committed 2026-10-07 13:13:45 +03:00
1 parent 718e9797eb
commit 640da1f27c
4 files changed
+138 -147

No files matched your search

+16 -116
View File
@@ -4,7 +4,7 @@
// =======================================================================
import { api } from './modules/api.js';
import { initTheme, openModal, closeModal, showToast, playTextSpeech } from './modules/ui.js';
import { initTheme, openModal, closeModal, showToast, playTextSpeech, switchView } from './modules/ui.js';
import { initDictionary, loadInitialData } from './modules/dictionary.js';
import { initSrs, startSrsTrainingSession, openStatsDashboard } from './modules/srs.js';
import { initReader, loadBookshelf, openBook } from './modules/reader.js';
@@ -81,25 +81,12 @@ export function applyInitialViewPreflight() {
} catch (e) {}
}
const dictionaryView = document.getElementById('dictionary-view');
const srsView = document.getElementById('srs-view');
const readerView = document.getElementById('reader-view');
const cefrView = document.getElementById('cefr-view');
const grammarView = document.getElementById('grammar-view');
const lessonView = document.getElementById('lesson-view');
const lessonRunnerView = document.getElementById('lesson-runner-view');
const bookshelfContainer = document.getElementById('bookshelf-container');
const readerInterface = document.getElementById('reader-interface');
const readerBookTitle = document.getElementById('reader-book-title');
if (hash.startsWith('#reader') || hash === '#bookshelf') {
if (dictionaryView) dictionaryView.classList.add('hidden');
if (srsView) srsView.classList.add('hidden');
if (cefrView) cefrView.classList.add('hidden');
if (grammarView) grammarView.classList.add('hidden');
if (lessonView) lessonView.classList.add('hidden');
if (lessonRunnerView) lessonRunnerView.classList.add('hidden');
if (readerView) readerView.classList.remove('hidden');
switchView('reader-view');
updateActiveNavState('reader');
if (hash.includes('/book/')) {
if (bookshelfContainer) bookshelfContainer.classList.add('hidden');
@@ -107,40 +94,16 @@ export function applyInitialViewPreflight() {
if (readerBookTitle) readerBookTitle.textContent = 'Загрузка книги...';
}
} else if (hash.startsWith('#srs')) {
if (dictionaryView) dictionaryView.classList.add('hidden');
if (readerView) readerView.classList.add('hidden');
if (cefrView) cefrView.classList.add('hidden');
if (grammarView) grammarView.classList.add('hidden');
if (lessonView) lessonView.classList.add('hidden');
if (lessonRunnerView) lessonRunnerView.classList.add('hidden');
if (srsView) srsView.classList.remove('hidden');
switchView('srs-view');
updateActiveNavState('srs');
} else if (hash.startsWith('#cefr')) {
if (dictionaryView) dictionaryView.classList.add('hidden');
if (readerView) readerView.classList.add('hidden');
if (srsView) srsView.classList.add('hidden');
if (grammarView) grammarView.classList.add('hidden');
if (lessonView) lessonView.classList.add('hidden');
if (lessonRunnerView) lessonRunnerView.classList.add('hidden');
if (cefrView) cefrView.classList.remove('hidden');
switchView('cefr-view');
updateActiveNavState('cefr');
} else if (hash.startsWith('#grammar')) {
if (dictionaryView) dictionaryView.classList.add('hidden');
if (readerView) readerView.classList.add('hidden');
if (srsView) srsView.classList.add('hidden');
if (cefrView) cefrView.classList.add('hidden');
if (lessonView) lessonView.classList.add('hidden');
if (lessonRunnerView) lessonRunnerView.classList.add('hidden');
if (grammarView) grammarView.classList.remove('hidden');
switchView('grammar-view');
updateActiveNavState('grammar');
} else if (hash.startsWith('#lesson')) {
if (dictionaryView) dictionaryView.classList.add('hidden');
if (readerView) readerView.classList.add('hidden');
if (srsView) srsView.classList.add('hidden');
if (cefrView) cefrView.classList.add('hidden');
if (grammarView) grammarView.classList.add('hidden');
if (lessonRunnerView) lessonRunnerView.classList.add('hidden');
if (lessonView) lessonView.classList.remove('hidden');
switchView('lesson-view');
updateActiveNavState('lesson');
}
}
@@ -153,17 +116,7 @@ export function openDictionaryView(updateHash = true) {
window.location.hash = '#dictionary';
return;
}
const dictionaryView = document.getElementById('dictionary-view');
const srsView = document.getElementById('srs-view');
const readerView = document.getElementById('reader-view');
const cefrView = document.getElementById('cefr-view');
const grammarView = document.getElementById('grammar-view');
if (srsView) srsView.classList.add('hidden');
if (readerView) readerView.classList.add('hidden');
if (cefrView) cefrView.classList.add('hidden');
if (grammarView) grammarView.classList.add('hidden');
if (dictionaryView) dictionaryView.classList.remove('hidden');
switchView('dictionary-view');
updateActiveNavState('dict');
try { localStorage.setItem('notes_active_view', 'dictionary-view'); } catch (e) {}
loadInitialData();
@@ -175,17 +128,7 @@ export function openSrsView(tagFilter = null, updateHash = true) {
window.location.hash = targetHash;
return;
}
const dictionaryView = document.getElementById('dictionary-view');
const srsView = document.getElementById('srs-view');
const readerView = document.getElementById('reader-view');
const cefrView = document.getElementById('cefr-view');
const grammarView = document.getElementById('grammar-view');
if (dictionaryView) dictionaryView.classList.add('hidden');
if (readerView) readerView.classList.add('hidden');
if (cefrView) cefrView.classList.add('hidden');
if (grammarView) grammarView.classList.add('hidden');
if (srsView) srsView.classList.remove('hidden');
switchView('srs-view');
updateActiveNavState('srs');
try { localStorage.setItem('notes_active_view', 'srs-view'); } catch (e) {}
startSrsTrainingSession(false, tagFilter);
@@ -200,19 +143,9 @@ export function openBookshelfView(updateHash = true) {
window.location.hash = '#reader';
return;
}
const dictionaryView = document.getElementById('dictionary-view');
const srsView = document.getElementById('srs-view');
const readerView = document.getElementById('reader-view');
const cefrView = document.getElementById('cefr-view');
const grammarView = document.getElementById('grammar-view');
switchView('reader-view');
const bookshelfContainer = document.getElementById('bookshelf-container');
const readerInterface = document.getElementById('reader-interface');
if (dictionaryView) dictionaryView.classList.add('hidden');
if (srsView) srsView.classList.add('hidden');
if (cefrView) cefrView.classList.add('hidden');
if (grammarView) grammarView.classList.add('hidden');
if (readerView) readerView.classList.remove('hidden');
if (bookshelfContainer) bookshelfContainer.classList.remove('hidden');
if (readerInterface) readerInterface.classList.add('hidden');
updateActiveNavState('reader');
@@ -242,18 +175,7 @@ export function openCefrView(level = null, mode = 'all', updateHash = true) {
return;
}
const dictionaryView = document.getElementById('dictionary-view');
const srsView = document.getElementById('srs-view');
const readerView = document.getElementById('reader-view');
const cefrView = document.getElementById('cefr-view');
const grammarView = document.getElementById('grammar-view');
if (dictionaryView) dictionaryView.classList.add('hidden');
if (srsView) srsView.classList.add('hidden');
if (readerView) readerView.classList.add('hidden');
if (grammarView) grammarView.classList.add('hidden');
if (cefrView) cefrView.classList.remove('hidden');
switchView('cefr-view');
updateActiveNavState('cefr');
try { localStorage.setItem('notes_active_view', 'cefr-view'); } catch (e) {}
@@ -272,18 +194,7 @@ export function openGrammarView(unitId = null, updateHash = true) {
return;
}
const dictionaryView = document.getElementById('dictionary-view');
const srsView = document.getElementById('srs-view');
const readerView = document.getElementById('reader-view');
const cefrView = document.getElementById('cefr-view');
const grammarView = document.getElementById('grammar-view');
if (dictionaryView) dictionaryView.classList.add('hidden');
if (srsView) srsView.classList.add('hidden');
if (readerView) readerView.classList.add('hidden');
if (cefrView) cefrView.classList.add('hidden');
if (grammarView) grammarView.classList.remove('hidden');
switchView('grammar-view');
updateActiveNavState('grammar');
try { localStorage.setItem('notes_active_view', 'grammar-view'); } catch (e) {}
@@ -301,22 +212,7 @@ export function openLessonView(presetId = null, updateHash = true) {
return;
}
const dictionaryView = document.getElementById('dictionary-view');
const srsView = document.getElementById('srs-view');
const readerView = document.getElementById('reader-view');
const cefrView = document.getElementById('cefr-view');
const grammarView = document.getElementById('grammar-view');
const lessonView = document.getElementById('lesson-view');
const lessonRunnerView = document.getElementById('lesson-runner-view');
if (dictionaryView) dictionaryView.classList.add('hidden');
if (srsView) srsView.classList.add('hidden');
if (readerView) readerView.classList.add('hidden');
if (cefrView) cefrView.classList.add('hidden');
if (grammarView) grammarView.classList.add('hidden');
if (lessonRunnerView) lessonRunnerView.classList.add('hidden');
if (lessonView) lessonView.classList.remove('hidden');
switchView('lesson-view');
updateActiveNavState('lesson');
try { localStorage.setItem('notes_active_view', 'lesson-view'); } catch (e) {}
@@ -352,6 +248,10 @@ export async function handleRouting() {
hash = '#grammar';
window.location.hash = hash;
return;
} else if (lastView === 'lesson-view') {
hash = '#lesson';
window.location.hash = hash;
return;
} else {
hash = '#dictionary';
}