Fix missing manga action execution failure messages
The manga actions to - download - delete downloads - mark as read - mark as unread did not show an error message in case the request to get relevant chapter ids failed.
This commit is contained in:
@@ -55,6 +55,8 @@ import type {
|
|||||||
UpdateMangaCategoriesPatchInput,
|
UpdateMangaCategoriesPatchInput,
|
||||||
} from '@/lib/graphql/generated/graphql-base.types.ts';
|
} from '@/lib/graphql/generated/graphql-base.types.ts';
|
||||||
|
|
||||||
|
const I18N_PLURAL = 9999;
|
||||||
|
|
||||||
type DownloadChaptersOptions = {
|
type DownloadChaptersOptions = {
|
||||||
size?: number;
|
size?: number;
|
||||||
onlyUnread?: boolean;
|
onlyUnread?: boolean;
|
||||||
@@ -190,6 +192,10 @@ export class Mangas {
|
|||||||
{ size, onlyUnread, downloadAhead = false }: DownloadChaptersOptions = {},
|
{ size, onlyUnread, downloadAhead = false }: DownloadChaptersOptions = {},
|
||||||
disableConfirmation?: boolean,
|
disableConfirmation?: boolean,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
return Mangas.executeAction(
|
||||||
|
'download',
|
||||||
|
I18N_PLURAL,
|
||||||
|
async () => {
|
||||||
const [chaptersToConsider, unReadDownloadedChapters] = await Promise.all([
|
const [chaptersToConsider, unReadDownloadedChapters] = await Promise.all([
|
||||||
Mangas.getChapterIdsWithState(mangaIds, {
|
Mangas.getChapterIdsWithState(mangaIds, {
|
||||||
isRead: onlyUnread ? false : undefined,
|
isRead: onlyUnread ? false : undefined,
|
||||||
@@ -206,11 +212,17 @@ export class Mangas {
|
|||||||
]) satisfies MangaIdToDownloadSize[];
|
]) satisfies MangaIdToDownloadSize[];
|
||||||
|
|
||||||
const mangaIdToChaptersToConsider = Object.groupBy(chaptersToConsider, ({ mangaId }) => mangaId);
|
const mangaIdToChaptersToConsider = Object.groupBy(chaptersToConsider, ({ mangaId }) => mangaId);
|
||||||
const mangaIdToUnReadDownloadedChapters = Object.groupBy(unReadDownloadedChapters, ({ mangaId }) => mangaId);
|
const mangaIdToUnReadDownloadedChapters = Object.groupBy(
|
||||||
|
unReadDownloadedChapters,
|
||||||
|
({ mangaId }) => mangaId,
|
||||||
|
);
|
||||||
|
|
||||||
const mangaIdToDownloadSize = Object.entries(mangaIdToUnReadDownloadedChapters).map(
|
const mangaIdToDownloadSize = Object.entries(mangaIdToUnReadDownloadedChapters).map(
|
||||||
([mangaId, downloadedChapters = []]) => {
|
([mangaId, downloadedChapters = []]) => {
|
||||||
const downloadAheadSize = Math.max(0, (size ?? downloadedChapters.length) - downloadedChapters.length);
|
const downloadAheadSize = Math.max(
|
||||||
|
0,
|
||||||
|
(size ?? downloadedChapters.length) - downloadedChapters.length,
|
||||||
|
);
|
||||||
const actualSize = downloadAhead ? downloadAheadSize : size;
|
const actualSize = downloadAhead ? downloadAheadSize : size;
|
||||||
|
|
||||||
return [mangaId, actualSize];
|
return [mangaId, actualSize];
|
||||||
@@ -245,12 +257,31 @@ export class Mangas {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Chapters.download(Chapters.getIds(chaptersToDownload), disableConfirmation);
|
try {
|
||||||
|
await Chapters.download(Chapters.getIds(chaptersToDownload), disableConfirmation);
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore - Error gets handled in Chapters
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async deleteChapters(mangaIds: number[], disableConfirmation?: boolean): Promise<void> {
|
static async deleteChapters(mangaIds: number[], disableConfirmation?: boolean): Promise<void> {
|
||||||
|
return Mangas.executeAction(
|
||||||
|
'delete',
|
||||||
|
I18N_PLURAL,
|
||||||
|
async () => {
|
||||||
const chapters = await Mangas.getChapterIdsWithState(mangaIds, { isDownloaded: true });
|
const chapters = await Mangas.getChapterIdsWithState(mangaIds, { isDownloaded: true });
|
||||||
return Chapters.delete(Chapters.getIds(chapters), disableConfirmation);
|
|
||||||
|
try {
|
||||||
|
await Chapters.delete(Chapters.getIds(chapters), disableConfirmation);
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore - Error gets handled in Chapters
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async markAsRead(
|
static async markAsRead(
|
||||||
@@ -258,18 +289,42 @@ export class Mangas {
|
|||||||
wasManuallyMarkedAsRead: boolean = false,
|
wasManuallyMarkedAsRead: boolean = false,
|
||||||
disableConfirmation?: boolean,
|
disableConfirmation?: boolean,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
return Mangas.executeAction(
|
||||||
|
'mark_as_read',
|
||||||
|
I18N_PLURAL,
|
||||||
|
async () => {
|
||||||
const chapters = await Mangas.getChapterIdsWithState(mangaIds, { isRead: false });
|
const chapters = await Mangas.getChapterIdsWithState(mangaIds, { isRead: false });
|
||||||
return Chapters.markAsRead(
|
|
||||||
|
try {
|
||||||
|
await Chapters.markAsRead(
|
||||||
chapters,
|
chapters,
|
||||||
wasManuallyMarkedAsRead,
|
wasManuallyMarkedAsRead,
|
||||||
mangaIds.length === 1 ? mangaIds[0] : undefined,
|
mangaIds.length === 1 ? mangaIds[0] : undefined,
|
||||||
disableConfirmation,
|
disableConfirmation,
|
||||||
);
|
);
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore - Error gets handled in Chapters
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async markAsUnread(mangaIds: number[], disableConfirmation?: boolean): Promise<void> {
|
static async markAsUnread(mangaIds: number[], disableConfirmation?: boolean): Promise<void> {
|
||||||
|
return Mangas.executeAction(
|
||||||
|
'mark_as_unread',
|
||||||
|
I18N_PLURAL,
|
||||||
|
async () => {
|
||||||
const chapters = await Mangas.getChapterIdsWithState(mangaIds, { isRead: true });
|
const chapters = await Mangas.getChapterIdsWithState(mangaIds, { isRead: true });
|
||||||
return Chapters.markAsUnread(Chapters.getIds(chapters), disableConfirmation);
|
|
||||||
|
try {
|
||||||
|
await Chapters.markAsUnread(Chapters.getIds(chapters), disableConfirmation);
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore - Error gets handled in Chapters
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async removeFromLibrary(mangaIds: number[], disableConfirmation?: boolean): Promise<void> {
|
static async removeFromLibrary(mangaIds: number[], disableConfirmation?: boolean): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user