Files
suwayomi-material-you-webui/src/typings.ts

414 lines
9.2 KiB
TypeScript
Raw Normal View History

/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
2021-01-26 23:32:12 +03:30
* 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/.
*/
2021-01-26 23:32:12 +03:30
import { OverridableComponent } from '@mui/material/OverridableComponent';
import { SvgIconTypeMap } from '@mui/material/SvgIcon/SvgIcon';
import { ParseKeys } from 'i18next';
import { Location } from 'react-router-dom';
type GenericLocation<State = any> = Omit<Location, 'state'> & { state?: State };
declare module 'react-router-dom' {
export function useParams<Params extends { [K in keyof Params]: string } = {}>(): Params;
export function useLocation<State = any>(): GenericLocation<State>;
}
export type TranslationKey = ParseKeys;
export interface IExtension {
name: string;
pkgName: string;
versionName: string;
versionCode: number;
lang: string;
isNsfw: boolean;
apkName: string;
iconUrl: string;
installed: boolean;
hasUpdate: boolean;
obsolete: boolean;
2020-12-24 16:50:50 +01:00
}
2020-12-25 06:36:34 +03:30
export interface ISource {
id: string;
name: string;
lang: string;
iconUrl: string;
supportsLatest: boolean;
isConfigurable: boolean;
isNsfw: boolean;
displayName: string;
2020-12-25 06:36:34 +03:30
}
2020-12-25 17:42:22 +01:00
export interface ISourceFilters {
type: string;
filter: ISourceFilter;
}
export interface ISourceFilter {
name: string;
state: number | string | boolean | ISourceFilters[] | IState;
values?: string[];
displayValues?: string[];
selected?: ISelected;
}
export interface ISelected {
displayname: string;
value: string;
_value: string;
}
export interface IState {
ascending: boolean;
index: number;
}
export interface IMetadataMigration {
appKeyPrefix?: { oldPrefix: string; newPrefix: string };
values?: {
/**
* In case the migration should only be applied to a specific metadata key.
* Otherwise, all metadata keys will get migrated.
*/
key?: string;
oldValue: string;
newValue: string;
}[];
keys?: { oldKey: string; newKey: string }[];
}
export type Metadata<Keys extends string = string, Values = string> = {
[key in Keys]: Values;
};
Save reader settings per manga in Meta (#216) * [#213] Add missing "meta" property - IManga - IMangaCard (optional) - IChapter - ICategory * [#213] Add util functions for handling metadata - global server - manga - chapter - category * [#213] Use "ReaderSettings" from the manga metadata - get ReaderSettings from manga metadata - remove unnecessary check "make sure settings has all the keys" in case the stored settings in the metadata are outdated they will be filled with default values * [#213] Reload manga only in case "mangaId" changed In case the chapter is still from the same manga, a reload is unnecessary * [#213] Only update the changed reader setting Otherwise the app has to send patch requests to the server for every setting even if it didn't change * [#213] Hide "openButton" on first render in case "navBar" is shown The "openButton" was always set to be visible event in case the navBar was shown on the first render * [#213] Open the "ReaderNavBar" if needed after receiving new settings Otherwise, the drawer won't open in case the "navBar" was hidden on the first render since the default state in that case was set to false * [#213] Update "ReaderSettings" after receiving the manga response Otherwise, the default settings aren't getting removed * [#213] Hide/Show "OpenButton" when opening/closing the drawer Otherwise, the button stays hidden until it gets updated due to scrolling * [#213] Keep "ReaderNavBar" state when opening prev/next chapter In case the navBar wasn't sticky but opened, it got closed when the prev/next chapter got opened * [#213] Prevent "ReaderNavBar" from closing when changing "staticNav" setting
2023-01-06 17:15:29 +01:00
export type MetadataHolder<Keys extends string = string, Values = string> = {
meta?: Metadata<Keys, Values>;
};
Save reader settings per manga in Meta (#216) * [#213] Add missing "meta" property - IManga - IMangaCard (optional) - IChapter - ICategory * [#213] Add util functions for handling metadata - global server - manga - chapter - category * [#213] Use "ReaderSettings" from the manga metadata - get ReaderSettings from manga metadata - remove unnecessary check "make sure settings has all the keys" in case the stored settings in the metadata are outdated they will be filled with default values * [#213] Reload manga only in case "mangaId" changed In case the chapter is still from the same manga, a reload is unnecessary * [#213] Only update the changed reader setting Otherwise the app has to send patch requests to the server for every setting even if it didn't change * [#213] Hide "openButton" on first render in case "navBar" is shown The "openButton" was always set to be visible event in case the navBar was shown on the first render * [#213] Open the "ReaderNavBar" if needed after receiving new settings Otherwise, the drawer won't open in case the "navBar" was hidden on the first render since the default state in that case was set to false * [#213] Update "ReaderSettings" after receiving the manga response Otherwise, the default settings aren't getting removed * [#213] Hide/Show "OpenButton" when opening/closing the drawer Otherwise, the button stays hidden until it gets updated due to scrolling * [#213] Keep "ReaderNavBar" state when opening prev/next chapter In case the navBar wasn't sticky but opened, it got closed when the prev/next chapter got opened * [#213] Prevent "ReaderNavBar" from closing when changing "staticNav" setting
2023-01-06 17:15:29 +01:00
export type AllowedMetadataValueTypes = string | boolean | number | undefined;
Save reader settings per manga in Meta (#216) * [#213] Add missing "meta" property - IManga - IMangaCard (optional) - IChapter - ICategory * [#213] Add util functions for handling metadata - global server - manga - chapter - category * [#213] Use "ReaderSettings" from the manga metadata - get ReaderSettings from manga metadata - remove unnecessary check "make sure settings has all the keys" in case the stored settings in the metadata are outdated they will be filled with default values * [#213] Reload manga only in case "mangaId" changed In case the chapter is still from the same manga, a reload is unnecessary * [#213] Only update the changed reader setting Otherwise the app has to send patch requests to the server for every setting even if it didn't change * [#213] Hide "openButton" on first render in case "navBar" is shown The "openButton" was always set to be visible event in case the navBar was shown on the first render * [#213] Open the "ReaderNavBar" if needed after receiving new settings Otherwise, the drawer won't open in case the "navBar" was hidden on the first render since the default state in that case was set to false * [#213] Update "ReaderSettings" after receiving the manga response Otherwise, the default settings aren't getting removed * [#213] Hide/Show "OpenButton" when opening/closing the drawer Otherwise, the button stays hidden until it gets updated due to scrolling * [#213] Keep "ReaderNavBar" state when opening prev/next chapter In case the navBar wasn't sticky but opened, it got closed when the prev/next chapter got opened * [#213] Prevent "ReaderNavBar" from closing when changing "staticNav" setting
2023-01-06 17:15:29 +01:00
export type MangaMetadataKeys = keyof IReaderSettings;
Save reader settings per manga in Meta (#216) * [#213] Add missing "meta" property - IManga - IMangaCard (optional) - IChapter - ICategory * [#213] Add util functions for handling metadata - global server - manga - chapter - category * [#213] Use "ReaderSettings" from the manga metadata - get ReaderSettings from manga metadata - remove unnecessary check "make sure settings has all the keys" in case the stored settings in the metadata are outdated they will be filled with default values * [#213] Reload manga only in case "mangaId" changed In case the chapter is still from the same manga, a reload is unnecessary * [#213] Only update the changed reader setting Otherwise the app has to send patch requests to the server for every setting even if it didn't change * [#213] Hide "openButton" on first render in case "navBar" is shown The "openButton" was always set to be visible event in case the navBar was shown on the first render * [#213] Open the "ReaderNavBar" if needed after receiving new settings Otherwise, the drawer won't open in case the "navBar" was hidden on the first render since the default state in that case was set to false * [#213] Update "ReaderSettings" after receiving the manga response Otherwise, the default settings aren't getting removed * [#213] Hide/Show "OpenButton" when opening/closing the drawer Otherwise, the button stays hidden until it gets updated due to scrolling * [#213] Keep "ReaderNavBar" state when opening prev/next chapter In case the navBar wasn't sticky but opened, it got closed when the prev/next chapter got opened * [#213] Prevent "ReaderNavBar" from closing when changing "staticNav" setting
2023-01-06 17:15:29 +01:00
export type SearchMetadataKeys = keyof ISearchSettings;
export type AppMetadataKeys = MangaMetadataKeys | SearchMetadataKeys;
Save reader settings per manga in Meta (#216) * [#213] Add missing "meta" property - IManga - IMangaCard (optional) - IChapter - ICategory * [#213] Add util functions for handling metadata - global server - manga - chapter - category * [#213] Use "ReaderSettings" from the manga metadata - get ReaderSettings from manga metadata - remove unnecessary check "make sure settings has all the keys" in case the stored settings in the metadata are outdated they will be filled with default values * [#213] Reload manga only in case "mangaId" changed In case the chapter is still from the same manga, a reload is unnecessary * [#213] Only update the changed reader setting Otherwise the app has to send patch requests to the server for every setting even if it didn't change * [#213] Hide "openButton" on first render in case "navBar" is shown The "openButton" was always set to be visible event in case the navBar was shown on the first render * [#213] Open the "ReaderNavBar" if needed after receiving new settings Otherwise, the drawer won't open in case the "navBar" was hidden on the first render since the default state in that case was set to false * [#213] Update "ReaderSettings" after receiving the manga response Otherwise, the default settings aren't getting removed * [#213] Hide/Show "OpenButton" when opening/closing the drawer Otherwise, the button stays hidden until it gets updated due to scrolling * [#213] Keep "ReaderNavBar" state when opening prev/next chapter In case the navBar wasn't sticky but opened, it got closed when the prev/next chapter got opened * [#213] Prevent "ReaderNavBar" from closing when changing "staticNav" setting
2023-01-06 17:15:29 +01:00
export type MetadataKeyValuePair = [AppMetadataKeys, AllowedMetadataValueTypes];
Save reader settings per manga in Meta (#216) * [#213] Add missing "meta" property - IManga - IMangaCard (optional) - IChapter - ICategory * [#213] Add util functions for handling metadata - global server - manga - chapter - category * [#213] Use "ReaderSettings" from the manga metadata - get ReaderSettings from manga metadata - remove unnecessary check "make sure settings has all the keys" in case the stored settings in the metadata are outdated they will be filled with default values * [#213] Reload manga only in case "mangaId" changed In case the chapter is still from the same manga, a reload is unnecessary * [#213] Only update the changed reader setting Otherwise the app has to send patch requests to the server for every setting even if it didn't change * [#213] Hide "openButton" on first render in case "navBar" is shown The "openButton" was always set to be visible event in case the navBar was shown on the first render * [#213] Open the "ReaderNavBar" if needed after receiving new settings Otherwise, the drawer won't open in case the "navBar" was hidden on the first render since the default state in that case was set to false * [#213] Update "ReaderSettings" after receiving the manga response Otherwise, the default settings aren't getting removed * [#213] Hide/Show "OpenButton" when opening/closing the drawer Otherwise, the button stays hidden until it gets updated due to scrolling * [#213] Keep "ReaderNavBar" state when opening prev/next chapter In case the navBar wasn't sticky but opened, it got closed when the prev/next chapter got opened * [#213] Prevent "ReaderNavBar" from closing when changing "staticNav" setting
2023-01-06 17:15:29 +01:00
export interface IMangaCard {
id: number;
title: string;
genre: string[];
thumbnailUrl: string;
unreadCount?: number;
downloadCount?: number;
inLibrary?: boolean;
meta?: Metadata;
inLibraryAt: number;
2023-03-05 12:26:50 +05:30
lastReadAt: number;
}
export interface IManga {
id: number;
sourceId: string;
url: string;
title: string;
thumbnailUrl: string;
artist: string;
author: string;
description: string;
genre: string[];
status: string;
2021-09-05 01:11:25 +04:30
inLibrary: boolean;
source: ISource;
2021-09-05 01:11:25 +04:30
meta: Metadata;
2021-09-05 01:11:25 +04:30
realUrl: string;
freshData: boolean;
unreadCount?: number;
downloadCount?: number;
age: number;
chaptersAge: number;
chaptersLastFetchedAt: number;
inLibraryAt: number;
initialized: boolean;
lastChapterRead: NullAndUndefined<IChapter>;
lastFetchedAt: number;
lastReadAt: number;
thumbnailUrlLastFetched: number;
updateStrategy: string;
2021-09-05 01:11:25 +04:30
}
export interface IChapter {
id: number;
url: string;
name: string;
uploadDate: number;
chapterNumber: number;
scanlator: string;
mangaId: number;
read: boolean;
bookmarked: boolean;
lastPageRead: number;
lastReadAt: number;
index: number;
fetchedAt: number;
chapterCount: number;
pageCount: number;
downloaded: boolean;
meta: Metadata;
2021-01-19 21:02:57 +03:30
}
2021-02-20 01:23:52 +03:30
export interface IMangaChapter {
manga: IManga;
chapter: IChapter;
2021-09-28 00:41:12 +03:30
}
export interface IPartialChapter {
pageCount: number;
index: number;
chapterCount: number;
lastPageRead: number;
2021-03-23 03:50:55 +04:30
}
export enum IncludeInGlobalUpdate {
EXCLUDE = 0,
INCLUDE = 1,
UNSET = -1,
}
export interface ICategory {
id: number;
order: number;
name: string;
default: boolean;
includeInUpdate: IncludeInGlobalUpdate;
meta: Metadata;
size: number;
2021-02-20 01:23:52 +03:30
}
2021-03-18 21:46:24 +03:30
export interface INavbarOverride {
status: boolean;
value: any;
2021-03-29 02:47:51 +04:30
}
2021-05-15 17:18:57 +04:30
export type ReaderType =
| 'ContinuesVertical'
| 'Webtoon'
| 'SingleVertical'
| 'SingleRTL'
| 'SingleLTR'
| 'DoubleVertical'
| 'DoubleRTL'
| 'DoubleLTR'
| 'ContinuesHorizontalLTR'
| 'ContinuesHorizontalRTL';
export interface IReaderSettings {
staticNav: boolean;
showPageNumber: boolean;
loadNextOnEnding: boolean;
skipDupChapters: boolean;
fitPageToWindow: boolean;
readerType: ReaderType;
2021-05-15 17:18:57 +04:30
}
export enum ChapterOffset {
PREV = -1,
NEXT = 1,
}
export interface ISearchSettings {
ignoreFilters: boolean;
}
export interface IReaderPage {
index: number;
src: string;
2021-05-15 17:18:57 +04:30
}
2021-05-15 23:22:37 +04:30
export interface IReaderProps {
pages: Array<IReaderPage>;
pageCount: number;
setCurPage: React.Dispatch<React.SetStateAction<number>>;
curPage: number;
initialPage: number;
settings: IReaderSettings;
manga: IMangaCard | IManga;
chapter: IChapter | IPartialChapter;
nextChapter: () => void;
prevChapter: () => void;
2021-05-15 23:22:37 +04:30
}
2021-05-25 21:06:27 +04:30
export interface IAbout {
name: string;
version: string;
revision: string;
buildType: 'Stable' | 'Preview';
buildTime: number;
github: string;
discord: string;
2021-05-25 21:06:27 +04:30
}
2021-05-30 04:01:49 +04:30
export interface IDownloadChapter {
chapterIndex: number;
mangaId: number;
state: 'Queued' | 'Downloading' | 'Finished' | 'Error';
progress: number;
chapter: IChapter;
manga: IManga;
2021-05-30 04:01:49 +04:30
}
export interface IQueue {
status: 'Stopped' | 'Started';
queue: IDownloadChapter[];
2021-05-30 04:01:49 +04:30
}
export interface IUpdateStatus {
running: boolean;
mangaStatusMap: {
COMPLETE?: IManga[];
RUNNING?: IManga[];
PENDING?: IManga[];
};
}
export interface PreferenceProps {
key: string;
title: string;
summary: string;
defaultValue: any;
currentValue: any;
defaultValueType: string;
2021-09-13 19:18:21 +04:30
// intetnal props
updateValue: any;
}
export interface TwoStatePreferenceProps extends PreferenceProps {
2021-09-13 19:18:21 +04:30
// intetnal props
type: 'Switch' | 'Checkbox';
2021-09-13 19:18:21 +04:30
}
export interface CheckBoxPreferenceProps extends PreferenceProps {}
export interface SwitchPreferenceCompatProps extends PreferenceProps {}
export interface ListPreferenceProps extends PreferenceProps {
entries: string[];
entryValues: string[];
2021-09-13 19:18:21 +04:30
}
export interface MultiSelectListPreferenceProps extends PreferenceProps {
entries: string[];
entryValues: string[];
}
export interface EditTextPreferenceProps extends PreferenceProps {
dialogTitle: string;
dialogMessage: string;
text: string;
2021-09-13 19:18:21 +04:30
}
export interface SourcePreferences {
type: string;
props: any;
}
export interface NavbarItem {
path: string;
title: TranslationKey;
SelectedIconComponent: OverridableComponent<SvgIconTypeMap<{}, 'svg'>>;
IconComponent: OverridableComponent<SvgIconTypeMap<{}, 'svg'>>;
show: 'mobile' | 'desktop' | 'both';
}
export interface PaginatedList<T> {
page: T[];
hasNextPage: boolean;
}
2021-12-13 19:52:56 +05:30
export type PaginatedMangaList = {
mangaList: IManga[];
hasNextPage: boolean;
};
export type NullAndUndefined<T> = T | null | undefined;
2021-12-13 19:52:56 +05:30
export type ChapterSortMode = 'fetchedAt' | 'source';
2021-12-13 19:52:56 +05:30
export interface ChapterListOptions {
active: boolean;
unread: NullAndUndefined<boolean>;
downloaded: NullAndUndefined<boolean>;
bookmarked: NullAndUndefined<boolean>;
reverse: boolean;
sortBy: ChapterSortMode;
showChapterNumber: boolean;
2021-12-13 19:52:56 +05:30
}
export type ChapterOptionsReducerAction =
| { type: 'filter'; filterType: string; filterValue: NullAndUndefined<boolean> }
| { type: 'sortBy'; sortBy: ChapterSortMode }
| { type: 'sortReverse' }
| { type: 'showChapterNumber' };
2022-03-03 18:19:01 +05:30
2023-03-05 12:26:50 +05:30
export type LibrarySortMode = 'sortToRead' | 'sortAlph' | 'sortDateAdded' | 'sortLastRead';
enum GridLayout {
Compact = 0,
Comfortable = 1,
List = 2,
}
export interface LibraryOptions {
// display options
showDownloadBadge: boolean;
showUnreadBadge: boolean;
gridLayout: GridLayout;
SourcegridLayout: GridLayout;
// filter options
downloaded: NullAndUndefined<boolean>;
unread: NullAndUndefined<boolean>;
sorts: NullAndUndefined<LibrarySortMode>;
sortDesc: NullAndUndefined<boolean>;
showTabSize: boolean;
2022-03-03 18:19:01 +05:30
}
export interface BatchChaptersChange {
delete?: boolean;
isRead?: boolean;
isBookmarked?: boolean;
lastPageRead?: number;
}
export type UpdateCheck = {
channel: 'Stable' | 'Preview';
tag: string;
url: string;
};
export type SourceSearchResult = {
mangaList: IManga[];
hasNextPage: boolean;
};
export type BackupValidationResult = {
missingSources: string[];
missingTrackers: string[];
mangasMissingSources: string[];
};