mirror of
https://github.com/C9Glax/tranga-website.git
synced 2025-10-11 13:19:49 +02:00
Add LibraryRefresh.tsx
This commit is contained in:
47
tranga-website/src/Components/Settings/LibraryRefresh.tsx
Normal file
47
tranga-website/src/Components/Settings/LibraryRefresh.tsx
Normal 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>
|
||||
);
|
||||
}
|
@@ -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<TrangaSettings | undefined>(undefined);
|
||||
|
||||
@@ -68,6 +69,7 @@ export default function Settings({ setApiUri }: { setApiUri: (uri: string) => vo
|
||||
<DownloadLanguage />
|
||||
<ChapterNamingScheme />
|
||||
<Maintenance />
|
||||
<LibraryRefresh />
|
||||
</AccordionGroup>
|
||||
</DialogContent>
|
||||
</ModalDialog>
|
||||
|
@@ -29,6 +29,7 @@ import {
|
||||
MetadataSearchResult,
|
||||
MinimalManga,
|
||||
NotificationConnector,
|
||||
PatchLibraryRefreshRecord,
|
||||
ProblemDetails,
|
||||
RequestType,
|
||||
TrangaSettings,
|
||||
@@ -1201,6 +1202,25 @@ export class V2<SecurityDataType = unknown> extends HttpClient<SecurityDataType>
|
||||
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<void, any>({
|
||||
path: `/v2/Settings/LibraryRefresh`,
|
||||
method: 'PATCH',
|
||||
body: data,
|
||||
type: ContentType.Json,
|
||||
...params,
|
||||
});
|
||||
/**
|
||||
* No description
|
||||
*
|
||||
|
@@ -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 */
|
||||
|
Reference in New Issue
Block a user