Files
odysseus/static/js/settings/writingStyle.js
T
Léo 8a95ec9299 refactor(settings): extract four panels into settings/ modules
static/js/settings.js was 5,721 lines behind a four-name public surface.
static/js/settings/ already existed with dom, registry, search, sidebar,
navigation and lifecycle, so this continues that package rather than
inventing a layout.

Moved verbatim, 407 lines:

  settings/speech.js        initTtsSettings, initSttSettings
  settings/writingStyle.js  initDocumentWritingStyle
  settings/imageModels.js   initImageSettings
  settings/agent.js         initAgentSettings
  settings/api.js           postSettings, lifted from _postSettings

These five were chosen because their only dependencies outside themselves
were el/byId, _postSettings and sortModelIds. Panels with wider reach stay
put: initEmailAccountsSettings, for instance, pulls a 64-declaration closure
covering most of the file, and splitting that is a design change rather than
a move.

settings.js keeps its public surface exactly: open, close,
refreshAiModelEndpoints and the default export, verified in a browser.

Three test updates the move required:

- tests/helpers/test_settings_shell_coordinator.mjs allowlists the real
  modules the coordinator may import, and rejected the new ones. That guard
  working is the reason to trust the rest of this diff.
- two source-introspection tests read settings.js for behaviour that now
  lives in a panel module. They read the whole settings surface now, so the
  next extraction does not break them again.
2026-09-30 09:04:20 +02:00

72 lines
2.8 KiB
JavaScript

// Document writing-style settings panel.
// Extracted verbatim from static/js/settings.js. Behaviour is unchanged: the
// functions moved, their bodies did not. settings.js imports them and calls
// them from the same places, so load order and init sequence are untouched.
import { byId as el } from './dom.js';
import { postSettings as _postSettings } from './api.js';
export async function initDocumentWritingStyle() {
const styleEl = el('set-document-style');
const saveBtn = el('set-document-style-save');
const extractBtn = el('set-document-style-extract');
const fileEl = el('set-document-style-file');
const msg = el('set-document-style-msg');
if (!styleEl || !saveBtn) return;
try {
const res = await fetch('/api/auth/settings', { credentials: 'same-origin' });
const data = await res.json();
styleEl.value = String(data.document_writing_style || '');
} catch (_) {
if (msg) msg.textContent = 'Failed to load';
}
saveBtn.addEventListener('click', async () => {
if (msg) msg.textContent = 'Saving...';
try {
const res = await _postSettings({ document_writing_style: styleEl.value });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
if (msg) msg.textContent = '✓ Saved';
} catch (_) {
if (msg) msg.textContent = 'Failed to save';
}
setTimeout(() => { if (msg) msg.textContent = ''; }, 3000);
});
extractBtn?.addEventListener('click', () => fileEl?.click());
fileEl?.addEventListener('change', async () => {
const file = fileEl.files?.[0];
if (!file) return;
extractBtn.disabled = true;
let whirlpool = null;
if (msg) {
msg.replaceChildren();
try {
const spinner = window.spinnerModule || (await import('./spinner.js')).default;
whirlpool = spinner.createWhirlpool(14);
whirlpool.element.style.cssText = 'display:inline-flex;width:14px;height:14px;margin-right:7px;';
const label = document.createElement('span');
label.textContent = 'Analyzing...';
msg.append(whirlpool.element, label);
} catch (_) {
msg.textContent = 'Analyzing...';
}
}
try {
const body = new FormData();
body.append('file', file);
const res = await fetch('/api/auth/settings/document-style/extract', {
method: 'POST', credentials: 'same-origin', body,
});
const data = await res.json().catch(() => ({}));
if (!res.ok || !data.style) throw new Error(data.detail || data.error || 'Extraction failed');
styleEl.value = String(data.style);
if (msg) msg.textContent = '✓ Extracted — review and save';
} catch (error) {
if (msg) msg.textContent = error.message || 'Extraction failed';
} finally {
whirlpool?.destroy?.();
extractBtn.disabled = false;
fileEl.value = '';
}
});
}