/* * Copyright (C) Contributors to the Suwayomi project * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { useTranslation } from 'react-i18next'; import { useContext, useEffect } from 'react'; import List from '@mui/material/List'; import { ListItem, ListItemText, Switch } from '@mui/material'; import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction'; import ListSubheader from '@mui/material/ListSubheader'; import { ServerDirSetting } from '@/components/settings/ServerDirSetting'; import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarContext.tsx'; import { ServerSettings } from '@/typings.ts'; import { requestManager } from '@/lib/requests/RequestManager.ts'; import { DownloadAheadSetting } from '@/components/settings/downloads/DownloadAheadSetting.tsx'; type DownloadSettingsType = Pick< ServerSettings, | 'downloadAsCbz' | 'downloadsPath' | 'autoDownloadNewChapters' | 'autoDownloadAheadLimit' | 'excludeEntryWithUnreadChapters' >; const extractDownloadSettings = (settings: ServerSettings): DownloadSettingsType => ({ downloadAsCbz: settings.downloadAsCbz, downloadsPath: settings.downloadsPath, autoDownloadNewChapters: settings.autoDownloadNewChapters, autoDownloadAheadLimit: settings.autoDownloadAheadLimit, excludeEntryWithUnreadChapters: settings.excludeEntryWithUnreadChapters, }); export const DownloadSettings = () => { const { t } = useTranslation(); const { setTitle, setAction } = useContext(NavBarContext); useSetDefaultBackTo('settings'); useEffect(() => { setTitle(t('download.settings.title')); setAction(null); }, [t]); const { data } = requestManager.useGetServerSettings(); const downloadSettings = data ? extractDownloadSettings(data.settings) : undefined; const [mutateSettings] = requestManager.useUpdateServerSettings(); const updateSetting = ( setting: Setting, value: DownloadSettingsType[Setting], ) => { mutateSettings({ variables: { input: { settings: { [setting]: value } } } }); }; return ( updateSetting('downloadsPath', path)} /> updateSetting('downloadAsCbz', e.target.checked)} /> {t('download.settings.auto_download.title')} } > updateSetting('autoDownloadNewChapters', e.target.checked)} /> {downloadSettings?.autoDownloadNewChapters ? ( updateSetting('excludeEntryWithUnreadChapters', e.target.checked)} /> ) : null} {t('download.settings.download_ahead.title')} } > ); };