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

383 lines
9.4 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';
2023-07-04 21:53:25 +02:00
import { ParseKeys } from 'i18next';
import { Location } from 'react-router-dom';
2023-09-25 23:32:26 +02:00
import {
2023-10-15 16:03:08 +02:00
GetCategoryQuery,
GetChapterQuery,
GetExtensionQuery,
GetMangaQuery,
GetServerSettingsQuery,
2023-09-25 23:32:26 +02:00
GetSourceQuery,
GetSourcesQuery,
2023-09-25 23:32:26 +02:00
MetaType,
SourcePreferenceChangeInput,
} from '@/lib/graphql/generated/graphql.ts';
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>;
}
2023-03-23 13:59:32 +01:00
2023-07-04 21:53:25 +02:00
export type TranslationKey = ParseKeys;
2023-10-15 16:03:08 +02:00
export type PartialExtension = GetExtensionQuery['extension'];
2020-12-25 06:36:34 +03:30
export interface ISource {
2023-02-06 10:06:33 +01:00
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 type TPartialSource = GetSourcesQuery['sources']['nodes'][number];
export type SourceFilters = GetSourceQuery['source']['filters'][number];
export interface IMetadataMigration {
2023-02-06 10:06:33 +01:00
appKeyPrefix?: { oldPrefix: string; newPrefix: string };
2023-02-17 13:10:44 +01:00
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;
}[];
2023-02-06 10:06:33 +01:00
keys?: { oldKey: string; newKey: string }[];
2023-01-06 18:19:45 +01:00
}
export type Metadata<Keys extends string = string, Values = string> = {
[key in Keys]: Values;
};
2023-09-08 00:44:01 +02:00
export type GqlMetaHolder = { meta?: MetaType[] };
export type MetadataHolder<Keys extends string = string, Values = string> = {
meta?: Metadata<Keys, Values>;
};
export type AllowedMetadataValueTypes = string | boolean | number | undefined;
2023-11-19 21:17:35 +01:00
export type MetadataServerSettingKeys = keyof MetadataServerSettings;
export type MangaMetadataKeys = keyof IReaderSettings;
export type SearchMetadataKeys = keyof ISearchSettings;
2023-11-19 21:17:35 +01:00
export type AppMetadataKeys = MetadataServerSettingKeys | MangaMetadataKeys | SearchMetadataKeys;
export type MetadataKeyValuePair = [AppMetadataKeys, AllowedMetadataValueTypes];
export interface IMangaCard {
2023-02-06 10:06:33 +01:00
id: number;
title: string;
2023-02-16 11:26:09 +05:30
genre: string[];
2023-02-06 10:06:33 +01:00
thumbnailUrl: string;
unreadCount?: number;
downloadCount?: number;
inLibrary?: boolean;
meta?: Metadata;
2023-03-04 22:21:39 +05:30
inLibraryAt: number;
2023-03-05 12:26:50 +05:30
lastReadAt: number;
2021-03-17 19:17:03 +03:30
}
2023-10-15 16:03:08 +02:00
export type TManga = GetMangaQuery['manga'];
export type TPartialManga = OptionalProperty<TManga, 'unreadCount' | 'downloadCount' | 'categories' | 'chapters'>;
export interface IManga {
2023-02-06 10:06:33 +01:00
id: number;
sourceId: string;
2021-03-17 19:17:03 +03:30
2023-02-06 10:06:33 +01:00
url: string;
title: string;
thumbnailUrl: string;
2021-03-17 19:17:03 +03:30
2023-02-06 10:06:33 +01:00
artist: string;
author: string;
description: string;
genre: string[];
status: string;
2021-09-05 01:11:25 +04:30
2023-02-06 10:06:33 +01:00
inLibrary: boolean;
source: ISource;
2021-09-05 01:11:25 +04:30
meta: Metadata;
2021-09-05 01:11:25 +04:30
2023-02-06 10:06:33 +01:00
realUrl: string;
freshData: boolean;
unreadCount?: number;
downloadCount?: number;
2022-11-02 10:42:02 +01:00
2023-02-06 10:06:33 +01:00
age: number;
chaptersAge: number;
2023-03-04 22:21:39 +05:30
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 {
2023-02-06 10:06:33 +01:00
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 {
2023-02-06 10:06:33 +01:00
manga: IManga;
chapter: IChapter;
2021-09-28 00:41:12 +03:30
}
2023-10-15 16:03:08 +02:00
export type TChapter = GetChapterQuery['chapter'];
export enum IncludeInGlobalUpdate {
EXCLUDE = 0,
INCLUDE = 1,
UNSET = -1,
}
2023-10-15 16:03:08 +02:00
export type TCategory = GetCategoryQuery['category'];
export interface ICategory {
2023-02-06 10:06:33 +01:00
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 {
2023-02-06 10:06:33 +01:00
status: boolean;
value: any;
2021-03-29 02:47:51 +04:30
}
2021-05-15 17:18:57 +04:30
export type ReaderType =
2023-02-06 10:06:33 +01:00
| 'ContinuesVertical'
| 'Webtoon'
| 'SingleVertical'
| 'SingleRTL'
| 'SingleLTR'
| 'DoubleVertical'
| 'DoubleRTL'
| 'DoubleLTR'
| 'ContinuesHorizontalLTR'
| 'ContinuesHorizontalRTL';
2021-05-15 23:22:37 +04:30
export interface IReaderSettings {
2023-02-06 10:06:33 +01:00
staticNav: boolean;
showPageNumber: boolean;
loadNextOnEnding: boolean;
skipDupChapters: boolean;
fitPageToWindow: boolean;
2023-02-06 10:06:33 +01:00
readerType: ReaderType;
offsetFirstPage: boolean;
2021-05-15 17:18:57 +04:30
}
export enum ChapterOffset {
PREV = -1,
NEXT = 1,
}
2023-11-19 21:17:35 +01:00
export type MetadataServerSettings = {
// downloads
2023-11-19 21:17:35 +01:00
deleteChaptersManuallyMarkedRead: boolean;
deleteChaptersWhileReading: number;
2023-11-19 21:17:35 +01:00
deleteChaptersWithBookmark: boolean;
// library
showAddToLibraryCategorySelectDialog: boolean;
ignoreFilters: boolean;
2023-11-19 21:17:35 +01:00
};
export interface ISearchSettings {
ignoreFilters: boolean;
}
export interface IReaderPage {
2023-02-06 10:06:33 +01:00
index: number;
src: string;
2021-05-15 17:18:57 +04:30
}
2021-05-15 23:22:37 +04:30
export interface IReaderProps {
2023-02-06 10:06:33 +01:00
pages: Array<IReaderPage>;
pageCount: number;
setCurPage: React.Dispatch<React.SetStateAction<number>>;
curPage: number;
initialPage: number;
settings: IReaderSettings;
2023-10-15 16:03:08 +02:00
manga: TManga;
chapter: TChapter;
2023-02-06 10:06:33 +01:00
nextChapter: () => void;
prevChapter: () => void;
2021-05-15 23:22:37 +04:30
}
2021-05-25 21:06:27 +04:30
export interface IDownloadChapter {
2023-02-06 10:06:33 +01:00
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 {
2023-02-06 10:06:33 +01:00
status: 'Stopped' | 'Started';
queue: IDownloadChapter[];
2021-05-30 04:01:49 +04:30
}
export interface IUpdateStatus {
2023-02-06 10:06:33 +01:00
running: boolean;
mangaStatusMap: {
2023-02-06 10:06:33 +01:00
COMPLETE?: IManga[];
RUNNING?: IManga[];
PENDING?: IManga[];
};
}
2023-09-25 23:32:26 +02:00
export type SourcePreferences = GetSourceQuery['source']['preferences'][number];
export interface PreferenceProps {
2023-09-25 23:32:26 +02:00
updateValue: <Key extends keyof Omit<SourcePreferenceChangeInput, 'position'>>(
type: Key,
value: SourcePreferenceChangeInput[Key],
) => void;
}
2021-09-13 19:18:21 +04:30
2023-09-25 23:32:26 +02:00
export type TwoStatePreferenceProps = (CheckBoxPreferenceProps | SwitchPreferenceCompatProps) & {
2021-09-13 19:18:21 +04:30
// intetnal props
2023-09-25 23:32:26 +02:00
twoStateType: 'Switch' | 'Checkbox';
};
2023-09-25 23:32:26 +02:00
export type CheckBoxPreferenceProps = PreferenceProps &
ExtractByKeyValue<SourcePreferences, '__typename', 'CheckBoxPreference'>;
2023-02-06 10:06:33 +01:00
2023-09-25 23:32:26 +02:00
export type SwitchPreferenceCompatProps = PreferenceProps &
ExtractByKeyValue<SourcePreferences, '__typename', 'SwitchPreference'>;
2023-09-25 23:32:26 +02:00
export type ListPreferenceProps = PreferenceProps &
ExtractByKeyValue<SourcePreferences, '__typename', 'ListPreference'>;
2023-09-25 23:32:26 +02:00
export type MultiSelectListPreferenceProps = PreferenceProps &
ExtractByKeyValue<SourcePreferences, '__typename', 'MultiSelectListPreference'>;
2023-09-25 23:32:26 +02:00
export type EditTextPreferenceProps = PreferenceProps &
ExtractByKeyValue<SourcePreferences, '__typename', 'EditTextPreference'>;
export interface NavbarItem {
2023-02-06 10:06:33 +01:00
path: string;
2023-03-23 13:59:32 +01:00
title: TranslationKey;
2023-02-06 10:06:33 +01:00
SelectedIconComponent: OverridableComponent<SvgIconTypeMap<{}, 'svg'>>;
IconComponent: OverridableComponent<SvgIconTypeMap<{}, 'svg'>>;
show: 'mobile' | 'desktop' | 'both';
}
2021-11-10 23:04:04 +03:30
export interface PaginatedList<T> {
2023-02-06 10:06:33 +01:00
page: T[];
hasNextPage: boolean;
2021-11-10 23:04:04 +03:30
}
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 {
2023-02-06 10:06:33 +01:00
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
}
2022-01-24 15:09:28 +05:30
export type ChapterOptionsReducerAction =
2023-02-06 10:06:33 +01:00
| { 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';
2022-11-24 09:41:03 +01:00
enum GridLayout {
Compact = 0,
Comfortable = 1,
List = 2,
}
export interface LibraryOptions {
2022-04-07 12:53:14 +02:00
// display options
2023-12-19 15:17:00 +01:00
showContinueReadingButton: boolean;
2023-02-06 10:06:33 +01:00
showDownloadBadge: boolean;
showUnreadBadge: boolean;
gridLayout: GridLayout;
SourcegridLayout: GridLayout;
2022-04-07 12:53:14 +02:00
// filter options
2023-02-06 10:06:33 +01:00
downloaded: NullAndUndefined<boolean>;
unread: NullAndUndefined<boolean>;
sorts: NullAndUndefined<LibrarySortMode>;
sortDesc: NullAndUndefined<boolean>;
showTabSize: boolean;
2022-03-03 18:19:01 +05:30
}
2022-11-21 01:33:21 +01:00
2023-05-18 13:25:19 +02:00
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[];
};
export type ServerSettings = GetServerSettingsQuery['settings'];