refac
This commit is contained in:
@@ -65,8 +65,13 @@
|
||||
defaultUserUiSettings = { ...defaultUserUiSettings, ...updated };
|
||||
};
|
||||
|
||||
const getDefaultUserUiSettings = () => {
|
||||
const value = adminConfig?.DEFAULT_UI_SETTINGS;
|
||||
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
||||
};
|
||||
|
||||
const updateHandler = async () => {
|
||||
adminConfig.DEFAULT_USER_UI_SETTINGS = defaultUserUiSettings;
|
||||
adminConfig.DEFAULT_UI_SETTINGS = defaultUserUiSettings;
|
||||
|
||||
const res = await updateAdminConfig(localStorage.token, adminConfig);
|
||||
|
||||
@@ -83,12 +88,7 @@
|
||||
|
||||
onMount(async () => {
|
||||
adminConfig = await getAdminConfig(localStorage.token);
|
||||
defaultUserUiSettings =
|
||||
adminConfig?.DEFAULT_USER_UI_SETTINGS &&
|
||||
typeof adminConfig.DEFAULT_USER_UI_SETTINGS === 'object' &&
|
||||
!Array.isArray(adminConfig.DEFAULT_USER_UI_SETTINGS)
|
||||
? adminConfig.DEFAULT_USER_UI_SETTINGS
|
||||
: {};
|
||||
defaultUserUiSettings = getDefaultUserUiSettings();
|
||||
|
||||
banners = [...$_banners];
|
||||
});
|
||||
@@ -396,7 +396,7 @@
|
||||
<div>{$i18n.t('Default Interface Settings')}</div>
|
||||
<div class="mt-1.5 text-[0.6875rem] text-gray-400 dark:text-gray-600">
|
||||
{$i18n.t(
|
||||
'Set the interface values new users start with. User changes still override these defaults.'
|
||||
'Set system-wide interface defaults for every account. Personal settings override these defaults.'
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
$: currentSettings = (settingsValue ?? $settings ?? {}) as Record<string, any>;
|
||||
$: externalSettings = settingsValue !== null;
|
||||
$: defaultSettings = ($config?.ui?.default_settings ?? {}) as Record<string, any>;
|
||||
|
||||
let backgroundImageUrl: string | null = null;
|
||||
let inputFiles: FileList | null = null;
|
||||
@@ -117,6 +118,11 @@
|
||||
const actionButtonClass =
|
||||
'text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-gray-500 dark:hover:text-white';
|
||||
|
||||
const matchesDefaultSetting = (key: string, value: unknown) =>
|
||||
!externalSettings &&
|
||||
Object.prototype.hasOwnProperty.call(defaultSettings, key) &&
|
||||
JSON.stringify(defaultSettings[key]) === JSON.stringify(value);
|
||||
|
||||
const toggleLandingPageMode = async () => {
|
||||
landingPageMode = landingPageMode === '' ? 'chat' : '';
|
||||
saveSettings({ landingPageMode: landingPageMode });
|
||||
@@ -309,6 +315,7 @@
|
||||
lastSettingsValue = settingsValue;
|
||||
init();
|
||||
}
|
||||
$: textScaleUsesDefault = textScale === null || matchesDefaultSetting('textScale', textScale);
|
||||
|
||||
onMount(async () => {
|
||||
init();
|
||||
@@ -376,13 +383,13 @@
|
||||
on:click={() => {
|
||||
if (textScale === null) {
|
||||
textScale = 1;
|
||||
} else {
|
||||
} else if (!textScaleUsesDefault) {
|
||||
textScale = null;
|
||||
setTextScaleHandler(1);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{#if textScale === null}
|
||||
{#if textScaleUsesDefault}
|
||||
<span>{$i18n.t('Default')}</span>
|
||||
{:else}
|
||||
<span>{textScale}x</span>
|
||||
|
||||
@@ -342,7 +342,7 @@ type Config = {
|
||||
auto_redirect?: boolean;
|
||||
};
|
||||
ui?: {
|
||||
default_user_settings?: Record<string, unknown>;
|
||||
default_settings?: Record<string, unknown>;
|
||||
pending_user_overlay_title?: string;
|
||||
pending_user_overlay_content?: string;
|
||||
response_watermark?: string;
|
||||
|
||||
Reference in New Issue
Block a user