diff --git a/packages/components/frontend/ConfigEditor.tsx b/packages/components/frontend/ConfigEditor.tsx index 213725df5..c32b5ea75 100644 --- a/packages/components/frontend/ConfigEditor.tsx +++ b/packages/components/frontend/ConfigEditor.tsx @@ -13,7 +13,7 @@ const locales = { }; function MonacoContainer({ - config, setValue, setError, monaco, schema, editorCallback, size, + config, setValue, setError, monaco, schema, editorCallback, size, dark, }) { const [editor, setEditor] = React.useState(null); const [model, setModel] = React.useState(null); @@ -69,7 +69,7 @@ function MonacoContainer({ const model = monaco.editor.createModel(config, 'yaml', monaco.Uri.parse('hydro://system/setting.yaml')); setModel(model); const e = monaco.editor.create(element, { - theme: 'vs-light', + theme: dark ? 'vs-dark' : 'vs-light', lineNumbers: 'off', glyphMargin: true, lightbulb: { enabled: monaco.editor.ShowLightbulbIconMode.On }, @@ -151,13 +151,14 @@ export default function ConfigEditor({ const [size, setSize] = React.useState([50, 50]); - return (
+ return (
{info}
diff --git a/packages/hydrooj/src/handler/manage.ts b/packages/hydrooj/src/handler/manage.ts index 107f05aef..e4de588e4 100644 --- a/packages/hydrooj/src/handler/manage.ts +++ b/packages/hydrooj/src/handler/manage.ts @@ -182,7 +182,7 @@ class SystemConfigHandler extends SystemHandler { @requireSudo async get() { this.response.template = 'manage_config.html'; - let value; + let value = this.ctx.setting.configSource; const processNode = (node: any, schema: Schema, parent?: any, accessKey?: string) => { if (['union', 'intersect'].includes(schema.type)) { @@ -198,16 +198,13 @@ class SystemConfigHandler extends SystemHandler { }; try { - try { - value = Schema.intersect(this.ctx.setting.settings)(yaml.load(this.ctx.setting.configSource)); - } catch (e) { - value = yaml.load(this.ctx.setting.configSource); - } - for (const schema of this.ctx.setting.settings) processNode(value, schema); + const temp = yaml.load(this.ctx.setting.configSource); + for (const schema of this.ctx.setting.settings) processNode(temp, schema); + value = yaml.dump(temp); } catch (e) { } this.response.body = { schema: Schema.intersect(this.ctx.setting.settings).toJSON(), - value: yaml.dump(value), + value, }; } diff --git a/packages/hydrooj/src/model/setting.ts b/packages/hydrooj/src/model/setting.ts index 1204620e5..a4d2de59b 100644 --- a/packages/hydrooj/src/model/setting.ts +++ b/packages/hydrooj/src/model/setting.ts @@ -26,11 +26,6 @@ for (const country of countries) { const timezones = Array.from(tzs).sort().map((tz) => [tz, tz]) as [string, string][]; const langRange: Dictionary = {}; -for (const lang in global.Hydro.locales) { - if (!global.Hydro.locales[lang].__interface) continue; - langRange[lang] = global.Hydro.locales[lang].__langname; -} - export const FLAG_HIDDEN = 1; export const FLAG_DISABLED = 2; export const FLAG_SECRET = 4; @@ -364,6 +359,10 @@ export const langs: Record = {}; export const inject = ['db']; export async function apply(ctx: Context) { logger.info('Ensuring settings'); + for (const lang in global.Hydro.locales) { + if (!global.Hydro.locales[lang].__interface) continue; + langRange[lang] = global.Hydro.locales[lang].__langname; + } const system = global.Hydro.model.system; for (const setting of SYSTEM_SETTINGS) { if (!setting.value) continue; diff --git a/packages/ui-default/pages/setting.page.tsx b/packages/ui-default/pages/setting.page.tsx index f5443cba3..aa308f4a3 100644 --- a/packages/ui-default/pages/setting.page.tsx +++ b/packages/ui-default/pages/setting.page.tsx @@ -7,6 +7,10 @@ import { NamedPage } from 'vj/misc/Page'; import { i18n, request } from 'vj/utils'; const page = new NamedPage('manage_config', async () => { + if (document.documentElement.className.includes('theme--dark')) { + document.documentElement.className += ' dark'; + } + const [{ ConfigEditor, ComponentsProvider }, { load }] = await Promise.all([ import('@hydrooj/components'), import('vj/components/monaco/loader'), @@ -35,6 +39,7 @@ const page = new NamedPage('manage_config', async () => { onSave={(value) => { request.post('', { value }).then(() => { Notification.success(i18n('Changes saved successfully')); + window.location.reload(); }).catch((e) => { Notification.error(i18n('Failed to save changes:'), e.message); }); diff --git a/packages/ui-default/templates/partials/footer.html b/packages/ui-default/templates/partials/footer.html index bd878d56e..1d75e740d 100644 --- a/packages/ui-default/templates/partials/footer.html +++ b/packages/ui-default/templates/partials/footer.html @@ -25,7 +25,7 @@
- @@ -42,11 +56,13 @@