Feature/gql improve queries mutations subscriptions (#470)

* [Codegen] Request less fields for category mutations

* [Codegen] Request less fields for chapter mutations

* [Codegen] Request less fields for downloader mutations

* [Codegen] Request less fields for extension mutations

* [Codegen] Request less fields for manga mutations

* [Codegen] Request less fields for source mutations

* [Codegen] Request less fields for updater subscription

* [Codegen] Request less fields for downloader subscription

* [Codegen] Combine chapter update mutations
This commit is contained in:
schroda
2023-11-24 03:17:49 +01:00
committed by GitHub
parent 3b147b1b46
commit 7adc28a35c
12 changed files with 443 additions and 198 deletions

View File

@@ -70,19 +70,16 @@ export const ChapterCard: React.FC<IProps> = (props: IProps) => {
const sendChange = <Key extends keyof UpdatePatchInput>(key: Key, value: UpdatePatchInput[Key]) => {
handleClose();
const shouldDeleteChapter = ({ isBookmarked, isDownloaded }: TChapter) =>
isDownloaded && (!isBookmarked || metadataServerSettings.deleteChaptersWithBookmark);
const isMarkAsRead = (key === 'isRead' && value) || key === 'markPrevRead';
const shouldAutoDeleteChapters = isMarkAsRead && metadataServerSettings.deleteChaptersManuallyMarkedRead;
if (shouldAutoDeleteChapters) {
const shouldDeleteChapter = ({ isBookmarked, isDownloaded }: TChapter) =>
isDownloaded && (!isBookmarked || metadataServerSettings.deleteChaptersWithBookmark);
const chaptersToDelete = key === 'isRead' ? [chapter] : allChapters;
const chapterIdsToDelete = chaptersToDelete
.filter(shouldDeleteChapter)
.map(({ id: chapterId }) => chapterId);
requestManager.deleteDownloadedChapters(chapterIdsToDelete).response.catch(() => {});
}
const chaptersToDelete = key === 'isRead' ? [chapter] : allChapters;
const chapterIdsToDelete = shouldAutoDeleteChapters
? chaptersToDelete.filter(shouldDeleteChapter).map(({ id: chapterId }) => chapterId)
: [];
if (key === 'markPrevRead') {
const index = allChapters.findIndex(({ id: chapterId }) => chapterId === chapter.id);
@@ -91,7 +88,7 @@ export const ChapterCard: React.FC<IProps> = (props: IProps) => {
.slice(index)
.filter(({ isRead }) => !isRead)
.map(({ id: chapterId }) => chapterId),
{ isRead: true },
{ isRead: true, chapterIdsToDelete },
);
return;
}
@@ -99,6 +96,7 @@ export const ChapterCard: React.FC<IProps> = (props: IProps) => {
requestManager.updateChapter(chapter.id, {
[key]: value,
lastPageRead: key === 'isRead' ? 0 : undefined,
deleteChapter: !!chapterIdsToDelete.length,
});
};

View File

@@ -164,21 +164,19 @@ export const ChapterList: React.FC<IProps> = ({ manga, isRefreshing }) => {
if (action === 'delete') {
actionPromise = requestManager.deleteDownloadedChapters(chapterIds).response;
} else {
actionPromise = requestManager.updateChapters(chapterIds, change).response;
}
const shouldDeleteChapters =
action === 'mark_as_read' && metadataServerSettings.deleteChaptersManuallyMarkedRead;
const chapterIdsToDelete = shouldDeleteChapters
? actionChapters
.filter(
({ chapter }) =>
chapter.isDownloaded &&
(!chapter.isBookmarked || metadataServerSettings.deleteChaptersWithBookmark),
)
.map(({ chapter }) => chapter.id)
: [];
const shouldDeleteChapters =
action === 'mark_as_read' && metadataServerSettings.deleteChaptersManuallyMarkedRead;
if (shouldDeleteChapters) {
const chapterIdsToDelete = actionChapters
.filter(
({ chapter }) =>
chapter.isDownloaded &&
(!chapter.isBookmarked || metadataServerSettings.deleteChaptersWithBookmark),
)
.map(({ chapter }) => chapter.id);
requestManager.deleteDownloadedChapters(chapterIdsToDelete).response.catch(() => {});
actionPromise = requestManager.updateChapters(chapterIds, { ...change, chapterIdsToDelete }).response;
}
}

View File

@@ -41,6 +41,14 @@ export const FULL_CATEGORY_FIELDS = gql`
}
`;
export const UPDATER_CATEGORY_FIELDS = gql`
fragment UPDATER_CATEGORY_FIELDS on CategoryType {
id
name
includeInUpdate
}
`;
export const PARTIAL_SOURCE_FIELDS = gql`
fragment PARTIAL_SOURCE_FIELDS on SourceType {
displayName
@@ -110,41 +118,41 @@ export const FULL_SOURCE_FIELDS = gql`
}
}
filters {
... on TriStateFilter {
type: __typename
name
TriStateFilterDefault: default
}
... on CheckBoxFilter {
type: __typename
CheckBoxFilterDefault: default
name
}
... on TextFilter {
type: __typename
name
TextFilterDefault: default
}
... on SortFilter {
type: __typename
values
name
SortFilterDefault: default {
ascending
index
}
}
... on SeparatorFilter {
... on HeaderFilter {
type: __typename
name
}
... on SelectFilter {
type: __typename
values
name
SelectFilterDefault: default
name
values
}
... on HeaderFilter {
... on TriStateFilter {
type: __typename
TriStateFilterDefault: default
name
}
... on TextFilter {
type: __typename
TextFilterDefault: default
name
}
... on SortFilter {
type: __typename
SortFilterDefault: default {
ascending
index
}
name
values
}
... on SeparatorFilter {
type: __typename
name
}
@@ -179,7 +187,7 @@ export const FULL_SOURCE_FIELDS = gql`
}
... on SortFilter {
type: __typename
SorSortFilterDefault: default {
SortFilterDefault: default {
ascending
index
}
@@ -283,6 +291,14 @@ export const FULL_MANGA_FIELDS = gql`
}
`;
export const UPDATER_MANGA_FIELDS = gql`
fragment UPDATER_MANGA_FIELDS on MangaType {
id
title
thumbnailUrl
}
`;
export const FULL_EXTENSION_FIELDS = gql`
fragment FULL_EXTENSION_FIELDS on ExtensionType {
apkName
@@ -300,11 +316,16 @@ export const FULL_EXTENSION_FIELDS = gql`
`;
export const FULL_DOWNLOAD_STATUS = gql`
${FULL_CHAPTER_FIELDS}
fragment FULL_DOWNLOAD_STATUS on DownloadStatus {
queue {
chapter {
...FULL_CHAPTER_FIELDS
id
name
sourceOrder
manga {
id
title
}
}
progress
state
@@ -321,15 +342,21 @@ export const PARTIAL_UPDATER_STATUS = gql`
`;
export const FULL_UPDATER_STATUS = gql`
${FULL_MANGA_FIELDS}
${UPDATER_MANGA_FIELDS}
${BASE_MANGA_FIELDS}
${PARTIAL_UPDATER_STATUS}
${FULL_CATEGORY_FIELDS}
${UPDATER_CATEGORY_FIELDS}
fragment FULL_UPDATER_STATUS on UpdateStatus {
...PARTIAL_UPDATER_STATUS
completeJobs {
mangas {
nodes {
...FULL_MANGA_FIELDS
...BASE_MANGA_FIELDS
unreadCount
downloadCount
chapters {
totalCount
}
}
totalCount
}
@@ -337,7 +364,7 @@ export const FULL_UPDATER_STATUS = gql`
failedJobs {
mangas {
nodes {
...FULL_MANGA_FIELDS
...UPDATER_MANGA_FIELDS
}
totalCount
}
@@ -345,7 +372,7 @@ export const FULL_UPDATER_STATUS = gql`
pendingJobs {
mangas {
nodes {
...FULL_MANGA_FIELDS
...UPDATER_MANGA_FIELDS
}
totalCount
}
@@ -353,7 +380,7 @@ export const FULL_UPDATER_STATUS = gql`
runningJobs {
mangas {
nodes {
...FULL_MANGA_FIELDS
...UPDATER_MANGA_FIELDS
}
totalCount
}
@@ -361,7 +388,7 @@ export const FULL_UPDATER_STATUS = gql`
skippedJobs {
mangas {
nodes {
...FULL_MANGA_FIELDS
...UPDATER_MANGA_FIELDS
}
totalCount
}
@@ -369,7 +396,7 @@ export const FULL_UPDATER_STATUS = gql`
updatingCategories {
categories {
nodes {
...FULL_CATEGORY_FIELDS
...UPDATER_CATEGORY_FIELDS
}
totalCount
}
@@ -377,7 +404,7 @@ export const FULL_UPDATER_STATUS = gql`
skippedCategories {
categories {
nodes {
...FULL_CATEGORY_FIELDS
...UPDATER_CATEGORY_FIELDS
}
totalCount
}

File diff suppressed because one or more lines are too long

View File

@@ -22,38 +22,35 @@ export const CREATE_CATEGORY = gql`
`;
export const DELETE_CATEGORY = gql`
${FULL_CATEGORY_FIELDS}
mutation DELETE_CATEGORY($input: DeleteCategoryInput!) {
deleteCategory(input: $input) {
clientMutationId
category {
...FULL_CATEGORY_FIELDS
id
}
}
}
`;
export const DELETE_CATEGORY_METADATA = gql`
${FULL_CATEGORY_FIELDS}
mutation DELETE_CATEGORY_METADATA($input: DeleteCategoryMetaInput!) {
deleteCategoryMeta(input: $input) {
clientMutationId
meta {
key
value
category {
...FULL_CATEGORY_FIELDS
}
}
category {
...FULL_CATEGORY_FIELDS
id
meta {
key
value
}
}
}
}
`;
export const SET_CATEGORY_METADATA = gql`
${FULL_CATEGORY_FIELDS}
mutation SET_CATEGORY_METADATA($input: SetCategoryMetaInput!) {
setCategoryMeta(input: $input) {
clientMutationId
@@ -61,7 +58,11 @@ export const SET_CATEGORY_METADATA = gql`
key
value
category {
...FULL_CATEGORY_FIELDS
id
meta {
key
value
}
}
}
}
@@ -69,36 +70,50 @@ export const SET_CATEGORY_METADATA = gql`
`;
export const UPDATE_CATEGORY = gql`
${FULL_CATEGORY_FIELDS}
mutation UPDATE_CATEGORY($input: UpdateCategoryInput!) {
mutation UPDATE_CATEGORY(
$input: UpdateCategoryInput!
$getDefault: Boolean!
$getIncludeInUpdate: Boolean!
$getName: Boolean!
) {
updateCategory(input: $input) {
clientMutationId
category {
...FULL_CATEGORY_FIELDS
id
default @include(if: $getDefault)
includeInUpdate @include(if: $getIncludeInUpdate)
name @include(if: $getName)
}
}
}
`;
export const UPDATE_CATEGORIES = gql`
${FULL_CATEGORY_FIELDS}
mutation UPDATE_CATEGORIES($input: UpdateCategoriesInput!) {
mutation UPDATE_CATEGORIES(
$input: UpdateCategoriesInput!
$getDefault: Boolean!
$getIncludeInUpdate: Boolean!
$getName: Boolean!
) {
updateCategories(input: $input) {
clientMutationId
categories {
...FULL_CATEGORY_FIELDS
id
default @include(if: $getDefault)
includeInUpdate @include(if: $getIncludeInUpdate)
name @include(if: $getName)
}
}
}
`;
export const UPDATE_CATEGORY_ORDER = gql`
${FULL_CATEGORY_FIELDS}
mutation UPDATE_CATEGORY_ORDER($input: UpdateCategoryOrderInput!) {
updateCategoryOrder(input: $input) {
clientMutationId
categories {
...FULL_CATEGORY_FIELDS
id
order
}
}
}

View File

@@ -10,7 +10,6 @@ import gql from 'graphql-tag';
import { FULL_CHAPTER_FIELDS } from '@/lib/graphql/Fragments';
export const DELETE_CHAPTER_METADATA = gql`
${FULL_CHAPTER_FIELDS}
mutation DELETE_CHAPTER_METADATA($input: DeleteChapterMetaInput!) {
deleteChapterMeta(input: $input) {
clientMutationId
@@ -18,11 +17,19 @@ export const DELETE_CHAPTER_METADATA = gql`
key
value
chapter {
...FULL_CHAPTER_FIELDS
id
meta {
key
value
}
}
}
chapter {
...FULL_CHAPTER_FIELDS
id
meta {
key
value
}
}
}
}
@@ -30,12 +37,12 @@ export const DELETE_CHAPTER_METADATA = gql`
// makes the server fetch and return the pages of a chapter
export const GET_CHAPTER_PAGES_FETCH = gql`
${FULL_CHAPTER_FIELDS}
mutation GET_CHAPTER_PAGES_FETCH($input: FetchChapterPagesInput!) {
fetchChapterPages(input: $input) {
clientMutationId
chapter {
...FULL_CHAPTER_FIELDS
id
pageCount
}
pages
}
@@ -56,7 +63,6 @@ export const GET_MANGA_CHAPTERS_FETCH = gql`
`;
export const SET_CHAPTER_METADATA = gql`
${FULL_CHAPTER_FIELDS}
mutation SET_CHAPTER_METADATA($input: SetChapterMetaInput!) {
setChapterMeta(input: $input) {
clientMutationId
@@ -64,7 +70,11 @@ export const SET_CHAPTER_METADATA = gql`
key
value
chapter {
...FULL_CHAPTER_FIELDS
id
meta {
key
value
}
}
}
}
@@ -72,25 +82,93 @@ export const SET_CHAPTER_METADATA = gql`
`;
export const UPDATE_CHAPTER = gql`
${FULL_CHAPTER_FIELDS}
mutation UPDATE_CHAPTER($input: UpdateChapterInput!) {
mutation UPDATE_CHAPTER(
$input: UpdateChapterInput!
$getBookmarked: Boolean!
$getRead: Boolean!
$getLastPageRead: Boolean!
$id: Int!
$deleteChapter: Boolean!
$mangaId: Int!
$downloadAhead: Boolean!
) {
updateChapter(input: $input) {
clientMutationId
chapter {
...FULL_CHAPTER_FIELDS
id
isBookmarked @include(if: $getBookmarked)
isRead @include(if: $getRead)
lastReadAt @include(if: $getRead)
lastPageRead @include(if: $getLastPageRead)
manga @include(if: $getRead) {
id
unreadCount
lastReadChapter {
id
}
}
}
}
deleteDownloadedChapter(input: { id: $id }) @include(if: $deleteChapter) {
clientMutationId
chapters {
id
isDownloaded
manga {
id
downloadCount
}
}
}
downloadAhead(input: { mangaIds: [$mangaId], latestReadChapterIds: [$id] }) @include(if: $downloadAhead) {
clientMutationId
}
}
`;
export const UPDATE_CHAPTERS = gql`
${FULL_CHAPTER_FIELDS}
mutation UPDATE_CHAPTERS($input: UpdateChaptersInput!) {
mutation UPDATE_CHAPTERS(
$input: UpdateChaptersInput!
$getBookmarked: Boolean!
$getRead: Boolean!
$getLastPageRead: Boolean!
$chapterIdsToDelete: [Int!]!
$deleteChapters: Boolean!
$mangaIds: [Int!]!
$lastReadChapterIds: [Int!]!
$downloadAhead: Boolean!
) {
updateChapters(input: $input) {
clientMutationId
chapters {
...FULL_CHAPTER_FIELDS
id
isBookmarked @include(if: $getBookmarked)
isRead @include(if: $getRead)
lastReadAt @include(if: $getRead)
lastPageRead @include(if: $getLastPageRead)
manga @include(if: $getRead) {
id
unreadCount
lastReadChapter {
id
}
}
}
}
deleteDownloadedChapters(input: { ids: $chapterIdsToDelete }) @include(if: $deleteChapters) {
clientMutationId
chapters {
id
isDownloaded
manga {
id
downloadCount
}
}
}
downloadAhead(input: { mangaIds: $mangaIds, latestReadChapterIds: $lastReadChapterIds })
@include(if: $downloadAhead) {
clientMutationId
}
}
`;

View File

@@ -7,7 +7,7 @@
*/
import gql from 'graphql-tag';
import { FULL_CHAPTER_FIELDS, FULL_DOWNLOAD_STATUS } from '@/lib/graphql/Fragments';
import { FULL_DOWNLOAD_STATUS } from '@/lib/graphql/Fragments';
export const CLEAR_DOWNLOADER = gql`
${FULL_DOWNLOAD_STATUS}
@@ -22,24 +22,24 @@ export const CLEAR_DOWNLOADER = gql`
`;
export const DELETE_DOWNLOADED_CHAPTER = gql`
${FULL_CHAPTER_FIELDS}
mutation DELETE_DOWNLOADED_CHAPTER($input: DeleteDownloadedChapterInput!) {
deleteDownloadedChapter(input: $input) {
clientMutationId
chapters {
...FULL_CHAPTER_FIELDS
id
isDownloaded
}
}
}
`;
export const DELETE_DOWNLOADED_CHAPTERS = gql`
${FULL_CHAPTER_FIELDS}
mutation DELETE_DOWNLOADED_CHAPTERS($input: DeleteDownloadedChaptersInput!) {
deleteDownloadedChapters(input: $input) {
clientMutationId
chapters {
...FULL_CHAPTER_FIELDS
id
isDownloaded
}
}
}
@@ -106,24 +106,22 @@ export const REORDER_CHAPTER_DOWNLOAD = gql`
`;
export const START_DOWNLOADER = gql`
${FULL_DOWNLOAD_STATUS}
mutation START_DOWNLOADER($input: StartDownloaderInput = {}) {
startDownloader(input: $input) {
clientMutationId
downloadStatus {
...FULL_DOWNLOAD_STATUS
state
}
}
}
`;
export const STOP_DOWNLOADER = gql`
${FULL_DOWNLOAD_STATUS}
mutation STOP_DOWNLOADER($input: StopDownloaderInput = {}) {
stopDownloader(input: $input) {
clientMutationId
downloadStatus {
...FULL_DOWNLOAD_STATUS
state
}
}
}

View File

@@ -23,24 +23,32 @@ export const GET_EXTENSIONS_FETCH = gql`
`;
export const UPDATE_EXTENSION = gql`
${FULL_EXTENSION_FIELDS}
mutation UPDATE_EXTENSION($input: UpdateExtensionInput!) {
updateExtension(input: $input) {
clientMutationId
extension {
...FULL_EXTENSION_FIELDS
apkName
versionName
versionCode
isInstalled
isObsolete
hasUpdate
}
}
}
`;
export const UPDATE_EXTENSIONS = gql`
${FULL_EXTENSION_FIELDS}
mutation UPDATE_EXTENSIONS($input: UpdateExtensionsInput!) {
updateExtensions(input: $input) {
clientMutationId
extensions {
...FULL_EXTENSION_FIELDS
apkName
versionName
versionCode
isInstalled
isObsolete
hasUpdate
}
}
}
@@ -50,10 +58,10 @@ export const INSTALL_EXTERNAL_EXTENSION = gql`
${FULL_EXTENSION_FIELDS}
mutation INSTALL_EXTERNAL_EXTENSION($file: Upload!) {
installExternalExtension(input: { extensionFile: $file }) {
clientMutationId
extension {
...FULL_EXTENSION_FIELDS
}
clientMutationId
}
}
`;

View File

@@ -10,7 +10,6 @@ import gql from 'graphql-tag';
import { FULL_MANGA_FIELDS } from '@/lib/graphql/Fragments';
export const DELETE_MANGA_METADATA = gql`
${FULL_MANGA_FIELDS}
mutation DELETE_MANGA_METADATA($input: DeleteMangaMetaInput!) {
deleteMangaMeta(input: $input) {
clientMutationId
@@ -18,11 +17,19 @@ export const DELETE_MANGA_METADATA = gql`
key
value
manga {
...FULL_MANGA_FIELDS
id
meta {
key
value
}
}
}
manga {
...FULL_MANGA_FIELDS
id
meta {
key
value
}
}
}
}
@@ -42,7 +49,6 @@ export const GET_MANGA_FETCH = gql`
`;
export const SET_MANGA_METADATA = gql`
${FULL_MANGA_FIELDS}
mutation SET_MANGA_METADATA($input: SetMangaMetaInput!) {
setMangaMeta(input: $input) {
clientMutationId
@@ -50,7 +56,11 @@ export const SET_MANGA_METADATA = gql`
key
value
manga {
...FULL_MANGA_FIELDS
id
meta {
key
value
}
}
}
}
@@ -58,48 +68,64 @@ export const SET_MANGA_METADATA = gql`
`;
export const UPDATE_MANGA = gql`
${FULL_MANGA_FIELDS}
mutation UPDATE_MANGA($input: UpdateMangaInput!) {
updateManga(input: $input) {
clientMutationId
manga {
...FULL_MANGA_FIELDS
}
}
}
`;
export const UPDATE_MANGA_CATEGORIES = gql`
${FULL_MANGA_FIELDS}
mutation UPDATE_MANGA_CATEGORIES($input: UpdateMangaCategoriesInput!) {
updateMangaCategories(input: $input) {
clientMutationId
manga {
...FULL_MANGA_FIELDS
id
inLibrary
inLibraryAt
}
}
}
`;
export const UPDATE_MANGAS = gql`
${FULL_MANGA_FIELDS}
mutation UPDATE_MANGAS($input: UpdateMangasInput!) {
updateMangas(input: $input) {
clientMutationId
mangas {
...FULL_MANGA_FIELDS
id
inLibrary
inLibraryAt
}
}
}
`;
export const UPDATE_MANGA_CATEGORIES = gql`
mutation UPDATE_MANGA_CATEGORIES($input: UpdateMangaCategoriesInput!) {
updateMangaCategories(input: $input) {
clientMutationId
manga {
id
categories {
nodes {
id
mangas {
totalCount
}
}
}
}
}
}
`;
export const UPDATE_MANGAS_CATEGORIES = gql`
${FULL_MANGA_FIELDS}
mutation UPDATE_MANGAS_CATEGORIES($input: UpdateMangasCategoriesInput!) {
updateMangasCategories(input: $input) {
clientMutationId
mangas {
...FULL_MANGA_FIELDS
id
categories {
nodes {
id
mangas {
totalCount
}
}
}
}
}
}

View File

@@ -7,7 +7,7 @@
*/
import gql from 'graphql-tag';
import { BASE_MANGA_FIELDS, FULL_SOURCE_FIELDS } from '@/lib/graphql/Fragments';
import { BASE_MANGA_FIELDS } from '@/lib/graphql/Fragments';
export const GET_SOURCE_MANGAS_FETCH = gql`
${BASE_MANGA_FIELDS}
@@ -23,12 +23,62 @@ export const GET_SOURCE_MANGAS_FETCH = gql`
`;
export const UPDATE_SOURCE_PREFERENCES = gql`
${FULL_SOURCE_FIELDS}
mutation UPDATE_SOURCE_PREFERENCES($input: UpdateSourcePreferenceInput!) {
updateSourcePreference(input: $input) {
clientMutationId
source {
...FULL_SOURCE_FIELDS
id
preferences {
... on CheckBoxPreference {
type: __typename
CheckBoxCheckBoxCurrentValue: currentValue
summary
CheckBoxDefault: default
key
CheckBoxTitle: title
}
... on EditTextPreference {
type: __typename
EditTextPreferenceCurrentValue: currentValue
EditTextPreferenceDefault: default
EditTextPreferenceTitle: title
text
summary
key
dialogTitle
dialogMessage
}
... on SwitchPreference {
type: __typename
SwitchPreferenceCurrentValue: currentValue
summary
key
SwitchPreferenceDefault: default
SwitchPreferenceTitle: title
}
... on MultiSelectListPreference {
type: __typename
dialogMessage
dialogTitle
MultiSelectListPreferenceTitle: title
summary
key
entryValues
entries
MultiSelectListPreferenceDefault: default
MultiSelectListPreferenceCurrentValue: currentValue
}
... on ListPreference {
type: __typename
ListPreferenceCurrentValue: currentValue
ListPreferenceDefault: default
ListPreferenceTitle: title
summary
key
entryValues
entries
}
}
}
}
}

View File

@@ -1465,13 +1465,24 @@ export class RequestManager {
public updateChapter(
id: number,
patch: UpdateChapterPatchInput,
patch: UpdateChapterPatchInput & { deleteChapter?: boolean; downloadAheadMangaId?: number },
options?: MutationOptions<UpdateChapterMutation, UpdateChapterMutationVariables>,
): AbortableApolloMutationResponse<UpdateChapterMutation> {
const { deleteChapter, downloadAheadMangaId = -1, ...updatePatch } = patch;
return this.doRequest<UpdateChapterMutation, UpdateChapterMutationVariables>(
GQLMethod.MUTATION,
UPDATE_CHAPTER,
{ input: { id, patch } },
{
id,
input: { id, patch: updatePatch },
getBookmarked: patch.isBookmarked != null,
getRead: patch.isRead != null,
getLastPageRead: patch.lastPageRead != null,
deleteChapter: !!deleteChapter,
mangaId: downloadAheadMangaId,
downloadAhead: downloadAheadMangaId !== -1,
},
options,
);
}
@@ -1499,13 +1510,27 @@ export class RequestManager {
public updateChapters(
ids: number[],
patch: UpdateChapterPatchInput,
patch: UpdateChapterPatchInput & { chapterIdsToDelete?: number[]; mangaIds?: number[] },
options?: MutationOptions<UpdateChaptersMutation, UpdateChaptersMutationVariables>,
): AbortableApolloMutationResponse<UpdateChaptersMutation> {
const { chapterIdsToDelete = [], mangaIds = [], ...updatePatch } = patch;
const downloadAhead = !!mangaIds.length;
return this.doRequest<UpdateChaptersMutation, UpdateChaptersMutationVariables>(
GQLMethod.MUTATION,
UPDATE_CHAPTERS,
{ input: { ids, patch } },
{
input: { ids, patch: updatePatch },
getBookmarked: patch.isBookmarked != null,
getRead: patch.isRead != null,
getLastPageRead: patch.lastPageRead != null,
chapterIdsToDelete,
deleteChapters: !!chapterIdsToDelete.length,
mangaIds,
downloadAhead,
lastReadChapterIds: downloadAhead ? ids : [],
},
{ refetchQueries: [GET_MANGA], ...options },
);
}
@@ -1658,7 +1683,12 @@ export class RequestManager {
return this.doRequest<UpdateCategoryMutation, UpdateCategoryMutationVariables>(
GQLMethod.MUTATION,
UPDATE_CATEGORY,
{ input: { id, patch } },
{
input: { id, patch },
getIncludeInUpdate: patch.includeInUpdate != null,
getDefault: patch.default != null,
getName: patch.name != null,
},
options,
);
}

View File

@@ -125,7 +125,6 @@ export function Reader() {
const { data: settingsData } = requestManager.useGetServerSettings();
const isDownloadAheadEnabled = !!settingsData?.settings.autoDownloadAheadLimit;
const [downloadAhead] = requestManager.useDownloadAhead();
const getLoadedChapter = () => {
const isAChapterLoaded = loadedChapter.current;
@@ -177,29 +176,22 @@ export function Reader() {
const { settings: metadataSettings } = useMetadataServerSettings();
const updateChapter = (patch: UpdateChapterPatchInput) => {
requestManager.updateChapter(chapter.id, patch).response.catch(() => {});
const shouldDeleteChapter =
patch.isRead &&
!!patch.isRead &&
metadataSettings.deleteChaptersAutoMarkedRead &&
chapter.isDownloaded &&
(!chapter.isBookmarked || metadataSettings.deleteChaptersWithBookmark);
if (shouldDeleteChapter) {
requestManager.deleteDownloadedChapter(chapter.id).response.catch(() => {});
}
const shouldDownloadAhead =
chapter.manga.inLibrary && !chapter.isRead && patch.isRead && isDownloadAheadEnabled;
if (shouldDownloadAhead) {
downloadAhead({
variables: {
input: {
mangaIds: [chapter.manga.id],
latestReadChapterIds: [chapter.id],
},
},
}).catch(() => {});
}
chapter.manga.inLibrary && !chapter.isRead && !!patch.isRead && isDownloadAheadEnabled;
requestManager
.updateChapter(chapter.id, {
...patch,
deleteChapter: shouldDeleteChapter,
downloadAheadMangaId: shouldDownloadAhead ? chapter.manga.id : undefined,
})
.response.catch(() => {});
};
const setSettingValue = (key: keyof IReaderSettings, value: string | boolean) => {