mirror of
https://github.com/C9Glax/tranga-website.git
synced 2025-10-11 13:19:49 +02:00
Merge pull request #171 from C9Glax/refresh-libraries
Refresh libraries setting
This commit is contained in:
49
tranga-website/src/Components/Settings/LibraryRefresh.tsx
Normal file
49
tranga-website/src/Components/Settings/LibraryRefresh.tsx
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
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, Typography} 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'}>
|
||||||
|
<Typography level={"body-md"}>Refresh after</Typography>
|
||||||
|
<RadioGroup value={value.setting} onChange={onSettingChanged}>
|
||||||
|
{Object.keys(LibraryRefreshSetting).map(e => (
|
||||||
|
<Radio key={e} value={e} label={e} />
|
||||||
|
))}
|
||||||
|
</RadioGroup>
|
||||||
|
<Typography level={"body-md"}>When {LibraryRefreshSetting.WhileDownloading} refresh every x-minutes:</Typography>
|
||||||
|
<Input value={value.refreshLibraryWhileDownloadingEveryMinutes??undefined} onChange={onMinutesChanged} type={"number"} />
|
||||||
|
<TButton onClick={updateSetting}>Update</TButton>
|
||||||
|
</SettingsItem>
|
||||||
|
);
|
||||||
|
}
|
@@ -8,7 +8,7 @@ import {
|
|||||||
DialogContent,
|
DialogContent,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
Modal,
|
Modal,
|
||||||
ModalDialog,
|
ModalDialog, Stack,
|
||||||
} from '@mui/joy';
|
} from '@mui/joy';
|
||||||
import './Settings.css';
|
import './Settings.css';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
@@ -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>
|
||||||
@@ -80,7 +82,11 @@ export function SettingsItem({ title, children }: { title: string; children: Rea
|
|||||||
return (
|
return (
|
||||||
<Accordion>
|
<Accordion>
|
||||||
<AccordionSummary>{title}</AccordionSummary>
|
<AccordionSummary>{title}</AccordionSummary>
|
||||||
<AccordionDetails>{children}</AccordionDetails>
|
<AccordionDetails>
|
||||||
|
<Stack gap={1} direction="column">
|
||||||
|
{children}
|
||||||
|
</Stack>
|
||||||
|
</AccordionDetails>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -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
|
||||||
*
|
*
|
||||||
|
@@ -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 */
|
||||||
|
Reference in New Issue
Block a user