cdafffaa70
Côté JS : décompose main.js en modules ES6 (state, services, ui, router) pour séparer les responsabilités et faciliter la maintenance. Côté Rust : ajoute 7 tests sur is_relevant_path (notify_watcher) pour couvrir les cas cachés/non-md ; couverture totale 77 % > seuil 60 %. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
75 lines
2.4 KiB
JavaScript
75 lines
2.4 KiB
JavaScript
import { appState } from './state/app-state.js';
|
|
import { listMdFiles } from './services/files.js';
|
|
import { renderSidebar } from './ui/sidebar.js';
|
|
import { loadPage } from './ui/reader.js';
|
|
import { saveRecent, renderRecents } from './ui/home.js';
|
|
|
|
const viewHome = document.getElementById('view-home');
|
|
const viewReader = document.getElementById('view-reader');
|
|
const sidebarEl = document.querySelector('#sidebar');
|
|
const content = document.querySelector('#content');
|
|
const win = window.__TAURI__.window.getCurrentWindow();
|
|
const titlebarTitle = document.getElementById('titlebar-title');
|
|
|
|
export function showHome() {
|
|
appState.currentPath = null;
|
|
appState.currentMode = null;
|
|
sidebarEl.innerHTML = '';
|
|
win.setTitle('Pena — Markdown Viewer');
|
|
titlebarTitle.textContent = 'Pena — Markdown Viewer';
|
|
viewReader.classList.add('hidden');
|
|
viewHome.classList.remove('hidden');
|
|
renderRecents(openPath);
|
|
}
|
|
|
|
export function showReader() {
|
|
viewHome.classList.add('hidden');
|
|
viewReader.classList.remove('hidden');
|
|
}
|
|
|
|
export async function openPath(path, mode) {
|
|
appState.currentPath = path;
|
|
appState.currentMode = mode;
|
|
saveRecent(path, mode);
|
|
|
|
if (mode === 'file') {
|
|
showReader();
|
|
const sep = path.includes('\\') ? '\\' : '/';
|
|
const parentDir = path.split(sep).slice(0, -1).join(sep);
|
|
try {
|
|
const files = await listMdFiles(parentDir);
|
|
sidebarEl.classList.remove('hidden');
|
|
content.style.marginLeft = '';
|
|
renderSidebar(parentDir, files, path, filePath => loadPage(filePath, appState.currentMode, sidebarEl));
|
|
} catch {
|
|
sidebarEl.innerHTML = '';
|
|
sidebarEl.classList.add('hidden');
|
|
content.style.marginLeft = '0';
|
|
}
|
|
await loadPage(path, appState.currentMode, sidebarEl);
|
|
return;
|
|
}
|
|
|
|
// mode === 'dir'
|
|
sidebarEl.classList.remove('hidden');
|
|
content.style.marginLeft = '';
|
|
|
|
try {
|
|
const files = await listMdFiles(path);
|
|
showReader();
|
|
|
|
const sep = path.includes('\\') ? '\\' : '/';
|
|
const home = files.find(f => {
|
|
const name = f.split(sep).pop();
|
|
return name === 'Home.md' || name === 'home.md';
|
|
});
|
|
|
|
const firstFile = home ?? files[0];
|
|
renderSidebar(path, files, firstFile, filePath => loadPage(filePath, appState.currentMode, sidebarEl));
|
|
await loadPage(firstFile, appState.currentMode, sidebarEl);
|
|
} catch (err) {
|
|
showReader();
|
|
content.innerHTML = `<p class="error">Impossible d'ouvrir le dossier : ${err}</p>`;
|
|
}
|
|
}
|