Remove redundant extract helper functions for server settings

Simplifies settings usage by directly accessing the `settings` object instead of relying on intermediary extraction functions. Improves code readability and reduces unnecessary abstraction.

Ensures consistency across all settings components for a cleaner and more efficient implementation.
This commit is contained in:
schroda
2025-09-08 00:46:57 +02:00
parent 47e93c774f
commit 94299433c8
7 changed files with 8 additions and 139 deletions

View File

@@ -16,7 +16,6 @@ import { MetadataUpdateSettings } from '@/features/app-updates/AppUpdateChecker.
import { MetadataThemeSettings } from '@/features/theme/AppTheme.types.ts';
import { GetServerSettingsQuery } from '@/lib/graphql/generated/graphql.ts';
import { MetadataHistorySettings } from '@/features/history/History.types.ts';
import { ServerSettings as GqlServerSettings } from '@/features/settings/Settings.types.ts';
export type MetadataServerSettingKeys = keyof MetadataServerSettings;
@@ -37,52 +36,6 @@ export interface ISearchSettings {
}
export type ServerSettings = Omit<GetServerSettingsQuery['settings'], '__typename'>;
export type ServerSettingsType = Pick<
GqlServerSettings,
| 'ip'
| 'port'
| 'socksProxyEnabled'
| 'socksProxyVersion'
| 'socksProxyHost'
| 'socksProxyPort'
| 'socksProxyUsername'
| 'socksProxyPassword'
| 'debugLogsEnabled'
| 'systemTrayEnabled'
| 'maxLogFiles'
| 'maxLogFileSize'
| 'maxLogFolderSize'
| 'authMode'
| 'authUsername'
| 'authPassword'
| 'jwtAudience'
| 'jwtTokenExpiry'
| 'jwtRefreshExpiry'
| 'flareSolverrEnabled'
| 'flareSolverrTimeout'
| 'flareSolverrUrl'
| 'flareSolverrSessionName'
| 'flareSolverrSessionTtl'
| 'flareSolverrAsResponseFallback'
| 'opdsUseBinaryFileSizes'
| 'opdsItemsPerPage'
| 'opdsEnablePageReadProgress'
| 'opdsMarkAsReadOnDownload'
| 'opdsShowOnlyUnreadChapters'
| 'opdsShowOnlyDownloadedChapters'
| 'opdsChapterSortOrder'
| 'koreaderSyncServerUrl'
| 'koreaderSyncUsername'
| 'koreaderSyncUserkey'
| 'koreaderSyncDeviceId'
| 'koreaderSyncChecksumMethod'
| 'koreaderSyncStrategy'
| 'koreaderSyncPercentageTolerance'
| 'databaseType'
| 'databaseUrl'
| 'databaseUsername'
| 'databasePassword'
>;
export type WebUISettingsType = Pick<
ServerSettings,

View File

@@ -47,16 +47,10 @@ const getSkipMangasText = (settings: GlobalUpdateSkipEntriesSettings) => {
return skipSettings.join(', ');
};
const extractSkipEntriesSettings = (serverSettings: ServerSettings): GlobalUpdateSkipEntriesSettings => ({
excludeCompleted: serverSettings.excludeCompleted,
excludeNotStarted: serverSettings.excludeNotStarted,
excludeUnreadChapters: serverSettings.excludeUnreadChapters,
});
export const GlobalUpdateSettingsEntries = ({ serverSettings }: { serverSettings: ServerSettings }) => {
const { t } = useTranslation();
const globalUpdateSettings = extractSkipEntriesSettings(serverSettings);
const globalUpdateSettings = serverSettings;
const [mutateSettings] = requestManager.useUpdateServerSettings();
const [dialogSettings, setDialogSettings] = useState<GlobalUpdateSkipEntriesSettings>(

View File

@@ -29,7 +29,6 @@ import {
} from '@/features/settings/services/ServerSettingsMetadata.ts';
import { makeToast } from '@/base/utils/Toast.ts';
import { MetadataUpdateSettings } from '@/features/app-updates/AppUpdateChecker.types.ts';
import { ServerSettings as GqlServerSettings, ServerSettingsType } from '@/features/settings/Settings.types.ts';
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
import { useAppTitle } from '@/features/navigation-bar/hooks/useAppTitle.ts';
import {
@@ -47,52 +46,7 @@ import {
} from '@/features/settings/Settings.constants.ts';
import { ServerAddressSetting } from '@/features/settings/components/ServerAddressSetting.tsx';
import { AuthManager } from '@/features/authentication/AuthManager.ts';
const extractServerSettings = (settings: GqlServerSettings): ServerSettingsType => ({
ip: settings.ip,
port: settings.port,
socksProxyEnabled: settings.socksProxyEnabled,
socksProxyVersion: settings.socksProxyVersion,
socksProxyHost: settings.socksProxyHost,
socksProxyPort: settings.socksProxyPort,
socksProxyUsername: settings.socksProxyUsername,
socksProxyPassword: settings.socksProxyPassword,
debugLogsEnabled: settings.debugLogsEnabled,
systemTrayEnabled: settings.systemTrayEnabled,
maxLogFiles: settings.maxLogFiles,
maxLogFileSize: settings.maxLogFileSize,
maxLogFolderSize: settings.maxLogFolderSize,
authMode: settings.authMode,
authUsername: settings.authUsername,
authPassword: settings.authPassword,
jwtAudience: settings.jwtAudience,
jwtTokenExpiry: settings.jwtTokenExpiry,
jwtRefreshExpiry: settings.jwtRefreshExpiry,
flareSolverrEnabled: settings.flareSolverrEnabled,
flareSolverrTimeout: settings.flareSolverrTimeout,
flareSolverrUrl: settings.flareSolverrUrl,
flareSolverrSessionName: settings.flareSolverrSessionName,
flareSolverrSessionTtl: settings.flareSolverrSessionTtl,
flareSolverrAsResponseFallback: settings.flareSolverrAsResponseFallback,
opdsUseBinaryFileSizes: settings.opdsUseBinaryFileSizes,
opdsItemsPerPage: settings.opdsItemsPerPage,
opdsEnablePageReadProgress: settings.opdsEnablePageReadProgress,
opdsMarkAsReadOnDownload: settings.opdsMarkAsReadOnDownload,
opdsShowOnlyUnreadChapters: settings.opdsShowOnlyUnreadChapters,
opdsShowOnlyDownloadedChapters: settings.opdsShowOnlyDownloadedChapters,
opdsChapterSortOrder: settings.opdsChapterSortOrder,
koreaderSyncServerUrl: settings.koreaderSyncServerUrl,
koreaderSyncUsername: settings.koreaderSyncUsername,
koreaderSyncUserkey: settings.koreaderSyncUserkey,
koreaderSyncDeviceId: settings.koreaderSyncDeviceId,
koreaderSyncChecksumMethod: settings.koreaderSyncChecksumMethod,
koreaderSyncStrategy: settings.koreaderSyncStrategy,
koreaderSyncPercentageTolerance: settings.koreaderSyncPercentageTolerance,
databaseType: settings.databaseType,
databaseUrl: settings.databaseUrl,
databaseUsername: settings.databaseUsername,
databasePassword: settings.databasePassword,
});
import { ServerSettings as ServerSettingsType } from '@/features/settings/Settings.types.ts';
const getLogFilesCleanupDisplayValue = (ttl: number): string => {
if (ttl === 0) {
@@ -202,7 +156,7 @@ export const ServerSettings = () => {
);
}
const serverSettings = extractServerSettings(data!.settings);
const serverSettings = data!.settings;
const authModeDisabled = !serverSettings.authUsername?.trim() || !serverSettings.authPassword?.trim();
const isH2Database = serverSettings.databaseType === DatabaseType.H2;

View File

@@ -25,7 +25,7 @@ import {
} from '@/features/settings/services/ServerSettingsMetadata.ts';
import { makeToast } from '@/base/utils/Toast.ts';
import { MetadataUpdateSettings } from '@/features/app-updates/AppUpdateChecker.types.ts';
import { ServerSettings, WebUISettingsType } from '@/features/settings/Settings.types.ts';
import { WebUISettingsType } from '@/features/settings/Settings.types.ts';
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
import { useAppTitle } from '@/features/navigation-bar/hooks/useAppTitle.ts';
import {
@@ -34,15 +34,6 @@ import {
WEB_UI_INTERFACE_SELECT_VALUES,
} from '@/features/settings/Settings.constants.ts';
const extractWebUISettings = (settings: ServerSettings): WebUISettingsType => ({
webUIFlavor: settings.webUIFlavor,
initialOpenInBrowserEnabled: settings.initialOpenInBrowserEnabled,
webUIInterface: settings.webUIInterface,
electronPath: settings.electronPath,
webUIChannel: settings.webUIChannel,
webUIUpdateCheckInterval: settings.webUIUpdateCheckInterval,
});
export const WebUISettings = () => {
const { t } = useTranslation();
@@ -108,7 +99,7 @@ export const WebUISettings = () => {
);
}
const webUISettings = extractWebUISettings(data!.settings);
const webUISettings = data!.settings;
const isCustomWebUI = webUISettings.webUIFlavor === WebUiFlavor.Custom;
return (