Add LibraryRefresh.tsx

This commit is contained in:
2025-09-21 17:34:30 +02:00
parent 4c6dfe22d1
commit 4decfff9ff
4 changed files with 89 additions and 1 deletions

View File

@@ -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<PatchLibraryRefreshRecord>({
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<HTMLInputElement> = (e) => {
setValue({...value, setting: LibraryRefreshSetting[e.target.value as keyof typeof LibraryRefreshSetting] });
}
const onMinutesChanged : ChangeEventHandler<HTMLInputElement> = (e) => {
setValue({...value, refreshLibraryWhileDownloadingEveryMinutes: e.target.valueAsNumber})
}
return (
<SettingsItem title={'Library Refresh'}>
<RadioGroup defaultValue={value.setting} onChange={onSettingChanged}>
{Object.keys(LibraryRefreshSetting).map(e => (
<Radio value={e}>{e}</Radio>
))}
</RadioGroup>
<Input defaultValue={value.refreshLibraryWhileDownloadingEveryMinutes??undefined} onChange={onMinutesChanged} type={"number"} />
<TButton onClick={updateSetting}>Update</TButton>
</SettingsItem>
);
}

View File

@@ -22,6 +22,7 @@ import Maintenance from './Maintenance.tsx';
import { ApiContext } from '../../contexts/ApiContext.tsx'; import { ApiContext } from '../../contexts/ApiContext.tsx';
import { TrangaSettings } from '../../api/data-contracts.ts'; import { TrangaSettings } from '../../api/data-contracts.ts';
import TInput from '../Inputs/TInput.tsx'; import TInput from '../Inputs/TInput.tsx';
import LibraryRefresh from "./LibraryRefresh.tsx";
export const SettingsContext = createContext<TrangaSettings | undefined>(undefined); export const SettingsContext = createContext<TrangaSettings | undefined>(undefined);
@@ -68,6 +69,7 @@ export default function Settings({ setApiUri }: { setApiUri: (uri: string) => vo
<DownloadLanguage /> <DownloadLanguage />
<ChapterNamingScheme /> <ChapterNamingScheme />
<Maintenance /> <Maintenance />
<LibraryRefresh />
</AccordionGroup> </AccordionGroup>
</DialogContent> </DialogContent>
</ModalDialog> </ModalDialog>

View File

@@ -29,6 +29,7 @@ import {
MetadataSearchResult, MetadataSearchResult,
MinimalManga, MinimalManga,
NotificationConnector, NotificationConnector,
PatchLibraryRefreshRecord,
ProblemDetails, ProblemDetails,
RequestType, RequestType,
TrangaSettings, TrangaSettings,
@@ -1201,6 +1202,25 @@ export class V2<SecurityDataType = unknown> extends HttpClient<SecurityDataType>
method: 'PATCH', method: 'PATCH',
...params, ...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<void, any>({
path: `/v2/Settings/LibraryRefresh`,
method: 'PATCH',
body: data,
type: ContentType.Json,
...params,
});
/** /**
* No description * No description
* *

View File

@@ -41,6 +41,13 @@ export enum LibraryType {
Kavita = 'Kavita', Kavita = 'Kavita',
} }
export enum LibraryRefreshSetting {
AfterAllFinished = 'AfterAllFinished',
AfterMangaFinished = 'AfterMangaFinished',
AfterEveryChapter = 'AfterEveryChapter',
WhileDownloading = 'WhileDownloading',
}
export enum CoverSize { export enum CoverSize {
Original = 'Original', Original = 'Original',
Large = 'Large', Large = 'Large',
@@ -463,6 +470,15 @@ export interface NotificationConnector {
key: string; 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 { export interface ProblemDetails {
type?: string | null; type?: string | null;
title?: string | null; title?: string | null;
@@ -474,7 +490,7 @@ export interface ProblemDetails {
} }
export interface TrangaSettings { export interface TrangaSettings {
downloadLocation?: string | null; defaultDownloadLocation?: string | null;
userAgent?: string | null; userAgent?: string | null;
/** @format int32 */ /** @format int32 */
imageCompression?: number; imageCompression?: number;
@@ -516,6 +532,9 @@ export interface TrangaSettings {
maxConcurrentDownloads?: number; maxConcurrentDownloads?: number;
/** @format int32 */ /** @format int32 */
maxConcurrentWorkers?: number; maxConcurrentWorkers?: number;
libraryRefreshSetting?: LibraryRefreshSetting;
/** @format int32 */
refreshLibraryWhileDownloadingEveryMinutes?: number;
} }
/** API.Workers.BaseWorker DTO */ /** API.Workers.BaseWorker DTO */