diff --git a/tranga-website/src/Components/Settings/LibraryRefresh.tsx b/tranga-website/src/Components/Settings/LibraryRefresh.tsx new file mode 100644 index 0000000..5792142 --- /dev/null +++ b/tranga-website/src/Components/Settings/LibraryRefresh.tsx @@ -0,0 +1,47 @@ +import {ChangeEventHandler, ReactNode, useContext, useState} from 'react'; +import {SettingsContext, SettingsItem} from './Settings.tsx'; +import {ApiContext} from '../../contexts/ApiContext.tsx'; +import TButton from "../Inputs/TButton.tsx"; +import {LibraryRefreshSetting, PatchLibraryRefreshRecord} from "../../api/data-contracts.ts"; +import {Input, Radio, RadioGroup} from "@mui/joy"; + +export default function LibraryRefresh(): ReactNode { + const settings = useContext(SettingsContext); + + const [value, setValue] = useState({ + setting: settings?.libraryRefreshSetting ?? LibraryRefreshSetting.AfterAllFinished, + refreshLibraryWhileDownloadingEveryMinutes: settings?.refreshLibraryWhileDownloadingEveryMinutes + }); + + const Api = useContext(ApiContext); + + const updateSetting = async () => { + try { + const response = await Api.settingsLibraryRefreshPartialUpdate(value); + if (response.ok) return Promise.resolve(); + else return Promise.reject(); + } catch { + return await Promise.reject(); + } + }; + + const onSettingChanged : ChangeEventHandler = (e) => { + setValue({...value, setting: LibraryRefreshSetting[e.target.value as keyof typeof LibraryRefreshSetting] }); + } + + const onMinutesChanged : ChangeEventHandler = (e) => { + setValue({...value, refreshLibraryWhileDownloadingEveryMinutes: e.target.valueAsNumber}) + } + + return ( + + + {Object.keys(LibraryRefreshSetting).map(e => ( + {e} + ))} + + + Update + + ); +} diff --git a/tranga-website/src/Components/Settings/Settings.tsx b/tranga-website/src/Components/Settings/Settings.tsx index d460846..dbc3602 100644 --- a/tranga-website/src/Components/Settings/Settings.tsx +++ b/tranga-website/src/Components/Settings/Settings.tsx @@ -22,6 +22,7 @@ import Maintenance from './Maintenance.tsx'; import { ApiContext } from '../../contexts/ApiContext.tsx'; import { TrangaSettings } from '../../api/data-contracts.ts'; import TInput from '../Inputs/TInput.tsx'; +import LibraryRefresh from "./LibraryRefresh.tsx"; export const SettingsContext = createContext(undefined); @@ -68,6 +69,7 @@ export default function Settings({ setApiUri }: { setApiUri: (uri: string) => vo + diff --git a/tranga-website/src/api/V2.ts b/tranga-website/src/api/V2.ts index 316a8cd..af61ff8 100644 --- a/tranga-website/src/api/V2.ts +++ b/tranga-website/src/api/V2.ts @@ -29,6 +29,7 @@ import { MetadataSearchResult, MinimalManga, NotificationConnector, + PatchLibraryRefreshRecord, ProblemDetails, RequestType, TrangaSettings, @@ -1201,6 +1202,25 @@ export class V2 extends HttpClient method: 'PATCH', ...params, }); + /** + * No description + * + * @tags Settings + * @name SettingsLibraryRefreshPartialUpdate + * @summary Sets the time when Libraries are refreshed + * @request PATCH:/v2/Settings/LibraryRefresh + */ + settingsLibraryRefreshPartialUpdate = ( + data: PatchLibraryRefreshRecord, + params: RequestParams = {} + ) => + this.request({ + path: `/v2/Settings/LibraryRefresh`, + method: 'PATCH', + body: data, + type: ContentType.Json, + ...params, + }); /** * No description * diff --git a/tranga-website/src/api/data-contracts.ts b/tranga-website/src/api/data-contracts.ts index 2368a92..8e36818 100644 --- a/tranga-website/src/api/data-contracts.ts +++ b/tranga-website/src/api/data-contracts.ts @@ -41,6 +41,13 @@ export enum LibraryType { Kavita = 'Kavita', } +export enum LibraryRefreshSetting { + AfterAllFinished = 'AfterAllFinished', + AfterMangaFinished = 'AfterMangaFinished', + AfterEveryChapter = 'AfterEveryChapter', + WhileDownloading = 'WhileDownloading', +} + export enum CoverSize { Original = 'Original', Large = 'Large', @@ -463,6 +470,15 @@ export interface NotificationConnector { key: string; } +export interface PatchLibraryRefreshRecord { + setting: LibraryRefreshSetting; + /** + * When API.Workers.LibraryRefreshSetting.WhileDownloading is selected, update the time between refreshes + * @format int32 + */ + refreshLibraryWhileDownloadingEveryMinutes?: number | null; +} + export interface ProblemDetails { type?: string | null; title?: string | null; @@ -474,7 +490,7 @@ export interface ProblemDetails { } export interface TrangaSettings { - downloadLocation?: string | null; + defaultDownloadLocation?: string | null; userAgent?: string | null; /** @format int32 */ imageCompression?: number; @@ -516,6 +532,9 @@ export interface TrangaSettings { maxConcurrentDownloads?: number; /** @format int32 */ maxConcurrentWorkers?: number; + libraryRefreshSetting?: LibraryRefreshSetting; + /** @format int32 */ + refreshLibraryWhileDownloadingEveryMinutes?: number; } /** API.Workers.BaseWorker DTO */