refactor(settings): split SettingsScreen into section components and pure helpers

SettingsScreen CC 23 -> below 10. Form parsing, change detection and the dark-theme check moved to utils/ with unit tests; the dark switch now reads the OS scheme instead of comparing the background colour. Adds characterization tests for the screen.
This commit is contained in:
evandro committed 2026-10-10 04:18:40 -03:00
1 parent cb6eda0562
commit 434cba2a69
10 files changed
+671 -338

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import { DEFAULT_SERVER_CONFIG, ServerConfig } from '../services/types';
export interface ServerConfigForm {
host: string;
port: string;
apiKey: string;
}
/** Turns the raw text fields of the settings form into a usable ServerConfig. */
export function buildServerConfig(form: ServerConfigForm): ServerConfig {
return {
host: form.host.trim() || DEFAULT_SERVER_CONFIG.host,
port: parseInt(form.port, 10) || DEFAULT_SERVER_CONFIG.port,
apiKey: form.apiKey.trim() || undefined,
};
}
/** True when the form differs from what is currently stored. */
export function isConfigChanged(form: ServerConfigForm, saved: ServerConfig): boolean {
return (
form.host !== saved.host ||
form.port !== saved.port.toString() ||
form.apiKey !== (saved.apiKey ?? '')
);
}
+7
View File
@@ -0,0 +1,7 @@
/** Whether the dark theme is in effect for a stored preference and the OS scheme. */
export function isDarkTheme(
preference: 'light' | 'dark' | 'system',
systemScheme: 'light' | 'dark',
): boolean {
return preference === 'dark' || (preference === 'system' && systemScheme === 'dark');
}