import { html, useState, useEffect } from './vendor/htm-preact.js'; import { t, getLocale, LOCALES } from './i18n.js'; import { ToggleSwitch, useSaver } from './settings-ui.js'; import { FolderPickerField } from './folder-tree.js'; // MeshBay's own locale codes (i18n.js LOCALES) to the language tag TMDB // expects. Duplicated from nothing: this is the only place it lives now that // the TMDB fields moved out of the monolithic settings page. const TMDB_LANGUAGE_BY_LOCALE = { en: 'en-US', fr: 'fr-FR', es: 'es-ES', 'pt-BR': 'pt-BR', 'zh-CN': 'zh-CN', ja: 'ja-JP', de: 'de-DE', it: 'it-IT', nl: 'nl-NL', pl: 'pl-PL', }; /** * The Videos app's operator settings: which folders it works over, and the * TMDB lookups it makes. * * Several folders now, not one. A film library is as likely to be two drives * as one, and the single-root model made the second one invisible — the * operator's only recourse was to point Videos at a parent containing both, * which pulls in everything else under it too. * * The TMDB parts are two independent settings that happen to sit together: * the on/off switch is per group, while the API key and the query language * are node-wide, because they are one operator's credential and one shared * cache (docs/mediacenter.md §5.5). They save separately for that reason. */ function VideoSettings({ roots, dirs, settings, saveDirectories, transport, signFn }) { const { busy, msg, run } = useSaver(); const [directories, setDirectories] = useState(settings.videoDirectories || []); const [tmdbEnabled, setTmdbEnabled] = useState(settings.tmdbEnabled !== false); const [token, setToken] = useState(''); const [language, setLanguage] = useState( settings.tmdbLanguage || TMDB_LANGUAGE_BY_LOCALE[getLocale()] || 'en-US'); useEffect(() => { setDirectories(settings.videoDirectories || []); }, [settings.videoDirectories]); useEffect(() => { setTmdbEnabled(settings.tmdbEnabled !== false); }, [settings.tmdbEnabled]); useEffect(() => { if (settings.tmdbLanguage) setLanguage(settings.tmdbLanguage); }, [settings.tmdbLanguage]); const current = settings.videoDirectories || []; const dirsDirty = directories.length !== current.length || directories.some((d, i) => d !== current[i]); return html`
${t('settings_node.tmdb_hint')}
${settings.tmdbTokenCustomized ? t('settings_node.tmdb_token_customized') : t('settings_app.tmdb_token_prompt')} ${' '} ${t('settings_app.tmdb_token_link')}
${t('settings_node.tmdb_language_hint')}
${msg}
`}