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

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` export const PARTIAL_SOURCE_FIELDS = gql`
fragment PARTIAL_SOURCE_FIELDS on SourceType { fragment PARTIAL_SOURCE_FIELDS on SourceType {
displayName displayName
@@ -110,41 +118,41 @@ export const FULL_SOURCE_FIELDS = gql`
} }
} }
filters { filters {
... on TriStateFilter {
type: __typename
name
TriStateFilterDefault: default
}
... on CheckBoxFilter { ... on CheckBoxFilter {
type: __typename type: __typename
CheckBoxFilterDefault: default CheckBoxFilterDefault: default
name name
} }
... on TextFilter { ... on HeaderFilter {
type: __typename
name
TextFilterDefault: default
}
... on SortFilter {
type: __typename
values
name
SortFilterDefault: default {
ascending
index
}
}
... on SeparatorFilter {
type: __typename type: __typename
name name
} }
... on SelectFilter { ... on SelectFilter {
type: __typename type: __typename
values
name
SelectFilterDefault: default 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 type: __typename
name name
} }
@@ -179,7 +187,7 @@ export const FULL_SOURCE_FIELDS = gql`
} }
... on SortFilter { ... on SortFilter {
type: __typename type: __typename
SorSortFilterDefault: default { SortFilterDefault: default {
ascending ascending
index 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` export const FULL_EXTENSION_FIELDS = gql`
fragment FULL_EXTENSION_FIELDS on ExtensionType { fragment FULL_EXTENSION_FIELDS on ExtensionType {
apkName apkName
@@ -300,11 +316,16 @@ export const FULL_EXTENSION_FIELDS = gql`
`; `;
export const FULL_DOWNLOAD_STATUS = gql` export const FULL_DOWNLOAD_STATUS = gql`
${FULL_CHAPTER_FIELDS}
fragment FULL_DOWNLOAD_STATUS on DownloadStatus { fragment FULL_DOWNLOAD_STATUS on DownloadStatus {
queue { queue {
chapter { chapter {
...FULL_CHAPTER_FIELDS id
name
sourceOrder
manga {
id
title
}
} }
progress progress
state state
@@ -321,15 +342,21 @@ export const PARTIAL_UPDATER_STATUS = gql`
`; `;
export const FULL_UPDATER_STATUS = gql` export const FULL_UPDATER_STATUS = gql`
${FULL_MANGA_FIELDS} ${UPDATER_MANGA_FIELDS}
${BASE_MANGA_FIELDS}
${PARTIAL_UPDATER_STATUS} ${PARTIAL_UPDATER_STATUS}
${FULL_CATEGORY_FIELDS} ${UPDATER_CATEGORY_FIELDS}
fragment FULL_UPDATER_STATUS on UpdateStatus { fragment FULL_UPDATER_STATUS on UpdateStatus {
...PARTIAL_UPDATER_STATUS ...PARTIAL_UPDATER_STATUS
completeJobs { completeJobs {
mangas { mangas {
nodes { nodes {
...FULL_MANGA_FIELDS ...BASE_MANGA_FIELDS
unreadCount
downloadCount
chapters {
totalCount
}
} }
totalCount totalCount
} }
@@ -337,7 +364,7 @@ export const FULL_UPDATER_STATUS = gql`
failedJobs { failedJobs {
mangas { mangas {
nodes { nodes {
...FULL_MANGA_FIELDS ...UPDATER_MANGA_FIELDS
} }
totalCount totalCount
} }
@@ -345,7 +372,7 @@ export const FULL_UPDATER_STATUS = gql`
pendingJobs { pendingJobs {
mangas { mangas {
nodes { nodes {
...FULL_MANGA_FIELDS ...UPDATER_MANGA_FIELDS
} }
totalCount totalCount
} }
@@ -353,7 +380,7 @@ export const FULL_UPDATER_STATUS = gql`
runningJobs { runningJobs {
mangas { mangas {
nodes { nodes {
...FULL_MANGA_FIELDS ...UPDATER_MANGA_FIELDS
} }
totalCount totalCount
} }
@@ -361,7 +388,7 @@ export const FULL_UPDATER_STATUS = gql`
skippedJobs { skippedJobs {
mangas { mangas {
nodes { nodes {
...FULL_MANGA_FIELDS ...UPDATER_MANGA_FIELDS
} }
totalCount totalCount
} }
@@ -369,7 +396,7 @@ export const FULL_UPDATER_STATUS = gql`
updatingCategories { updatingCategories {
categories { categories {
nodes { nodes {
...FULL_CATEGORY_FIELDS ...UPDATER_CATEGORY_FIELDS
} }
totalCount totalCount
} }
@@ -377,7 +404,7 @@ export const FULL_UPDATER_STATUS = gql`
skippedCategories { skippedCategories {
categories { categories {
nodes { nodes {
...FULL_CATEGORY_FIELDS ...UPDATER_CATEGORY_FIELDS
} }
totalCount 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` export const DELETE_CATEGORY = gql`
${FULL_CATEGORY_FIELDS}
mutation DELETE_CATEGORY($input: DeleteCategoryInput!) { mutation DELETE_CATEGORY($input: DeleteCategoryInput!) {
deleteCategory(input: $input) { deleteCategory(input: $input) {
clientMutationId clientMutationId
category { category {
...FULL_CATEGORY_FIELDS id
} }
} }
} }
`; `;
export const DELETE_CATEGORY_METADATA = gql` export const DELETE_CATEGORY_METADATA = gql`
${FULL_CATEGORY_FIELDS}
mutation DELETE_CATEGORY_METADATA($input: DeleteCategoryMetaInput!) { mutation DELETE_CATEGORY_METADATA($input: DeleteCategoryMetaInput!) {
deleteCategoryMeta(input: $input) { deleteCategoryMeta(input: $input) {
clientMutationId clientMutationId
meta { meta {
key key
value
category {
...FULL_CATEGORY_FIELDS
}
} }
category { category {
...FULL_CATEGORY_FIELDS id
meta {
key
value
}
} }
} }
} }
`; `;
export const SET_CATEGORY_METADATA = gql` export const SET_CATEGORY_METADATA = gql`
${FULL_CATEGORY_FIELDS}
mutation SET_CATEGORY_METADATA($input: SetCategoryMetaInput!) { mutation SET_CATEGORY_METADATA($input: SetCategoryMetaInput!) {
setCategoryMeta(input: $input) { setCategoryMeta(input: $input) {
clientMutationId clientMutationId
@@ -61,7 +58,11 @@ export const SET_CATEGORY_METADATA = gql`
key key
value value
category { category {
...FULL_CATEGORY_FIELDS id
meta {
key
value
}
} }
} }
} }
@@ -69,36 +70,50 @@ export const SET_CATEGORY_METADATA = gql`
`; `;
export const UPDATE_CATEGORY = gql` export const UPDATE_CATEGORY = gql`
${FULL_CATEGORY_FIELDS} mutation UPDATE_CATEGORY(
mutation UPDATE_CATEGORY($input: UpdateCategoryInput!) { $input: UpdateCategoryInput!
$getDefault: Boolean!
$getIncludeInUpdate: Boolean!
$getName: Boolean!
) {
updateCategory(input: $input) { updateCategory(input: $input) {
clientMutationId clientMutationId
category { category {
...FULL_CATEGORY_FIELDS id
default @include(if: $getDefault)
includeInUpdate @include(if: $getIncludeInUpdate)
name @include(if: $getName)
} }
} }
} }
`; `;
export const UPDATE_CATEGORIES = gql` export const UPDATE_CATEGORIES = gql`
${FULL_CATEGORY_FIELDS} mutation UPDATE_CATEGORIES(
mutation UPDATE_CATEGORIES($input: UpdateCategoriesInput!) { $input: UpdateCategoriesInput!
$getDefault: Boolean!
$getIncludeInUpdate: Boolean!
$getName: Boolean!
) {
updateCategories(input: $input) { updateCategories(input: $input) {
clientMutationId clientMutationId
categories { categories {
...FULL_CATEGORY_FIELDS id
default @include(if: $getDefault)
includeInUpdate @include(if: $getIncludeInUpdate)
name @include(if: $getName)
} }
} }
} }
`; `;
export const UPDATE_CATEGORY_ORDER = gql` export const UPDATE_CATEGORY_ORDER = gql`
${FULL_CATEGORY_FIELDS}
mutation UPDATE_CATEGORY_ORDER($input: UpdateCategoryOrderInput!) { mutation UPDATE_CATEGORY_ORDER($input: UpdateCategoryOrderInput!) {
updateCategoryOrder(input: $input) { updateCategoryOrder(input: $input) {
clientMutationId clientMutationId
categories { 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'; import { FULL_CHAPTER_FIELDS } from '@/lib/graphql/Fragments';
export const DELETE_CHAPTER_METADATA = gql` export const DELETE_CHAPTER_METADATA = gql`
${FULL_CHAPTER_FIELDS}
mutation DELETE_CHAPTER_METADATA($input: DeleteChapterMetaInput!) { mutation DELETE_CHAPTER_METADATA($input: DeleteChapterMetaInput!) {
deleteChapterMeta(input: $input) { deleteChapterMeta(input: $input) {
clientMutationId clientMutationId
@@ -18,11 +17,19 @@ export const DELETE_CHAPTER_METADATA = gql`
key key
value value
chapter { chapter {
...FULL_CHAPTER_FIELDS id
meta {
key
value
}
} }
} }
chapter { 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 // makes the server fetch and return the pages of a chapter
export const GET_CHAPTER_PAGES_FETCH = gql` export const GET_CHAPTER_PAGES_FETCH = gql`
${FULL_CHAPTER_FIELDS}
mutation GET_CHAPTER_PAGES_FETCH($input: FetchChapterPagesInput!) { mutation GET_CHAPTER_PAGES_FETCH($input: FetchChapterPagesInput!) {
fetchChapterPages(input: $input) { fetchChapterPages(input: $input) {
clientMutationId clientMutationId
chapter { chapter {
...FULL_CHAPTER_FIELDS id
pageCount
} }
pages pages
} }
@@ -56,7 +63,6 @@ export const GET_MANGA_CHAPTERS_FETCH = gql`
`; `;
export const SET_CHAPTER_METADATA = gql` export const SET_CHAPTER_METADATA = gql`
${FULL_CHAPTER_FIELDS}
mutation SET_CHAPTER_METADATA($input: SetChapterMetaInput!) { mutation SET_CHAPTER_METADATA($input: SetChapterMetaInput!) {
setChapterMeta(input: $input) { setChapterMeta(input: $input) {
clientMutationId clientMutationId
@@ -64,7 +70,11 @@ export const SET_CHAPTER_METADATA = gql`
key key
value value
chapter { chapter {
...FULL_CHAPTER_FIELDS id
meta {
key
value
}
} }
} }
} }
@@ -72,25 +82,93 @@ export const SET_CHAPTER_METADATA = gql`
`; `;
export const UPDATE_CHAPTER = gql` export const UPDATE_CHAPTER = gql`
${FULL_CHAPTER_FIELDS} mutation UPDATE_CHAPTER(
mutation UPDATE_CHAPTER($input: UpdateChapterInput!) { $input: UpdateChapterInput!
$getBookmarked: Boolean!
$getRead: Boolean!
$getLastPageRead: Boolean!
$id: Int!
$deleteChapter: Boolean!
$mangaId: Int!
$downloadAhead: Boolean!
) {
updateChapter(input: $input) { updateChapter(input: $input) {
clientMutationId clientMutationId
chapter { 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` export const UPDATE_CHAPTERS = gql`
${FULL_CHAPTER_FIELDS} mutation UPDATE_CHAPTERS(
mutation UPDATE_CHAPTERS($input: UpdateChaptersInput!) { $input: UpdateChaptersInput!
$getBookmarked: Boolean!
$getRead: Boolean!
$getLastPageRead: Boolean!
$chapterIdsToDelete: [Int!]!
$deleteChapters: Boolean!
$mangaIds: [Int!]!
$lastReadChapterIds: [Int!]!
$downloadAhead: Boolean!
) {
updateChapters(input: $input) { updateChapters(input: $input) {
clientMutationId clientMutationId
chapters { 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 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` export const CLEAR_DOWNLOADER = gql`
${FULL_DOWNLOAD_STATUS} ${FULL_DOWNLOAD_STATUS}
@@ -22,24 +22,24 @@ export const CLEAR_DOWNLOADER = gql`
`; `;
export const DELETE_DOWNLOADED_CHAPTER = gql` export const DELETE_DOWNLOADED_CHAPTER = gql`
${FULL_CHAPTER_FIELDS}
mutation DELETE_DOWNLOADED_CHAPTER($input: DeleteDownloadedChapterInput!) { mutation DELETE_DOWNLOADED_CHAPTER($input: DeleteDownloadedChapterInput!) {
deleteDownloadedChapter(input: $input) { deleteDownloadedChapter(input: $input) {
clientMutationId clientMutationId
chapters { chapters {
...FULL_CHAPTER_FIELDS id
isDownloaded
} }
} }
} }
`; `;
export const DELETE_DOWNLOADED_CHAPTERS = gql` export const DELETE_DOWNLOADED_CHAPTERS = gql`
${FULL_CHAPTER_FIELDS}
mutation DELETE_DOWNLOADED_CHAPTERS($input: DeleteDownloadedChaptersInput!) { mutation DELETE_DOWNLOADED_CHAPTERS($input: DeleteDownloadedChaptersInput!) {
deleteDownloadedChapters(input: $input) { deleteDownloadedChapters(input: $input) {
clientMutationId clientMutationId
chapters { chapters {
...FULL_CHAPTER_FIELDS id
isDownloaded
} }
} }
} }
@@ -106,24 +106,22 @@ export const REORDER_CHAPTER_DOWNLOAD = gql`
`; `;
export const START_DOWNLOADER = gql` export const START_DOWNLOADER = gql`
${FULL_DOWNLOAD_STATUS}
mutation START_DOWNLOADER($input: StartDownloaderInput = {}) { mutation START_DOWNLOADER($input: StartDownloaderInput = {}) {
startDownloader(input: $input) { startDownloader(input: $input) {
clientMutationId clientMutationId
downloadStatus { downloadStatus {
...FULL_DOWNLOAD_STATUS state
} }
} }
} }
`; `;
export const STOP_DOWNLOADER = gql` export const STOP_DOWNLOADER = gql`
${FULL_DOWNLOAD_STATUS}
mutation STOP_DOWNLOADER($input: StopDownloaderInput = {}) { mutation STOP_DOWNLOADER($input: StopDownloaderInput = {}) {
stopDownloader(input: $input) { stopDownloader(input: $input) {
clientMutationId clientMutationId
downloadStatus { downloadStatus {
...FULL_DOWNLOAD_STATUS state
} }
} }
} }

View File

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

View File

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

View File

@@ -7,7 +7,7 @@
*/ */
import gql from 'graphql-tag'; 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` export const GET_SOURCE_MANGAS_FETCH = gql`
${BASE_MANGA_FIELDS} ${BASE_MANGA_FIELDS}
@@ -23,12 +23,62 @@ export const GET_SOURCE_MANGAS_FETCH = gql`
`; `;
export const UPDATE_SOURCE_PREFERENCES = gql` export const UPDATE_SOURCE_PREFERENCES = gql`
${FULL_SOURCE_FIELDS}
mutation UPDATE_SOURCE_PREFERENCES($input: UpdateSourcePreferenceInput!) { mutation UPDATE_SOURCE_PREFERENCES($input: UpdateSourcePreferenceInput!) {
updateSourcePreference(input: $input) { updateSourcePreference(input: $input) {
clientMutationId clientMutationId
source { 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( public updateChapter(
id: number, id: number,
patch: UpdateChapterPatchInput, patch: UpdateChapterPatchInput & { deleteChapter?: boolean; downloadAheadMangaId?: number },
options?: MutationOptions<UpdateChapterMutation, UpdateChapterMutationVariables>, options?: MutationOptions<UpdateChapterMutation, UpdateChapterMutationVariables>,
): AbortableApolloMutationResponse<UpdateChapterMutation> { ): AbortableApolloMutationResponse<UpdateChapterMutation> {
const { deleteChapter, downloadAheadMangaId = -1, ...updatePatch } = patch;
return this.doRequest<UpdateChapterMutation, UpdateChapterMutationVariables>( return this.doRequest<UpdateChapterMutation, UpdateChapterMutationVariables>(
GQLMethod.MUTATION, GQLMethod.MUTATION,
UPDATE_CHAPTER, 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, options,
); );
} }
@@ -1499,13 +1510,27 @@ export class RequestManager {
public updateChapters( public updateChapters(
ids: number[], ids: number[],
patch: UpdateChapterPatchInput, patch: UpdateChapterPatchInput & { chapterIdsToDelete?: number[]; mangaIds?: number[] },
options?: MutationOptions<UpdateChaptersMutation, UpdateChaptersMutationVariables>, options?: MutationOptions<UpdateChaptersMutation, UpdateChaptersMutationVariables>,
): AbortableApolloMutationResponse<UpdateChaptersMutation> { ): AbortableApolloMutationResponse<UpdateChaptersMutation> {
const { chapterIdsToDelete = [], mangaIds = [], ...updatePatch } = patch;
const downloadAhead = !!mangaIds.length;
return this.doRequest<UpdateChaptersMutation, UpdateChaptersMutationVariables>( return this.doRequest<UpdateChaptersMutation, UpdateChaptersMutationVariables>(
GQLMethod.MUTATION, GQLMethod.MUTATION,
UPDATE_CHAPTERS, 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 }, { refetchQueries: [GET_MANGA], ...options },
); );
} }
@@ -1658,7 +1683,12 @@ export class RequestManager {
return this.doRequest<UpdateCategoryMutation, UpdateCategoryMutationVariables>( return this.doRequest<UpdateCategoryMutation, UpdateCategoryMutationVariables>(
GQLMethod.MUTATION, GQLMethod.MUTATION,
UPDATE_CATEGORY, UPDATE_CATEGORY,
{ input: { id, patch } }, {
input: { id, patch },
getIncludeInUpdate: patch.includeInUpdate != null,
getDefault: patch.default != null,
getName: patch.name != null,
},
options, options,
); );
} }

View File

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