diff --git a/src/database/queries/ChapterQueries.ts b/src/database/queries/ChapterQueries.ts index 5d9b54ec..7c10a7b1 100644 --- a/src/database/queries/ChapterQueries.ts +++ b/src/database/queries/ChapterQueries.ts @@ -195,6 +195,17 @@ export const markChapterRead = async (chapterId: number) => { }); }; +export const markChaptersRead = async (chapterIds: number[]) => { + db.transaction(tx => { + tx.executeSql( + `UPDATE Chapter SET \`unread\` = 0 WHERE id IN (${chapterIds.join(',')})`, + undefined, + noop, + txnErrorCallback, + ); + }); +}; + const markChapterUnreadQuery = 'UPDATE Chapter SET `unread` = 1 WHERE id = ?'; export const markChapterUnread = async (chapterId: number) => { @@ -203,6 +214,17 @@ export const markChapterUnread = async (chapterId: number) => { }); }; +export const markChaptersUnread = async (chapterIds: number[]) => { + db.transaction(tx => { + tx.executeSql( + `UPDATE Chapter SET \`unread\` = 1 WHERE id IN (${chapterIds.join(',')})`, + undefined, + noop, + txnErrorCallback, + ); + }); +}; + const markAllChaptersReadQuery = 'UPDATE Chapter SET `unread` = 0 WHERE novelId = ?'; diff --git a/src/hooks/persisted/useNovel.ts b/src/hooks/persisted/useNovel.ts index 43feb0ce..5ae603b2 100644 --- a/src/hooks/persisted/useNovel.ts +++ b/src/hooks/persisted/useNovel.ts @@ -13,9 +13,10 @@ import { import { bookmarkChapter as _bookmarkChapter, markChapterRead as _markChapterRead, + markChaptersRead as _markChaptersRead, markPreviuschaptersRead as _markPreviuschaptersRead, markPreviousChaptersUnread as _markPreviousChaptersUnread, - markChapterUnread as _markChapterUnread, + markChaptersUnread as _markChaptersUnread, deleteChapter as _deleteChapter, deleteChapters as _deleteChapters, getPageChapters as _getPageChapters, @@ -234,10 +235,12 @@ export const useNovel = (novelPath: string, pluginId: string) => { }; const markChaptersRead = (_chapters: ChapterInfo[]) => { - _chapters.map(chapter => _markChapterRead(chapter.id)); + const chapterIds = _chapters.map(chapter => chapter.id); + _markChaptersRead(chapterIds); + setChapters( chapters.map(chapter => { - if (_chapters.some(c => c.id === chapter.id)) { + if (chapterIds.includes(chapter.id)) { return { ...chapter, unread: false, @@ -260,10 +263,12 @@ export const useNovel = (novelPath: string, pluginId: string) => { }; const markChaptersUnread = (_chapters: ChapterInfo[]) => { - _chapters.map(chapter => _markChapterUnread(chapter.id)); + const chapterIds = _chapters.map(chapter => chapter.id); + _markChaptersUnread(chapterIds); + setChapters( chapters.map(chapter => { - if (_chapters.some(c => c.id === chapter.id)) { + if (chapterIds.includes(chapter.id)) { return { ...chapter, unread: true,