fix: Optimize Marking Chapters as Read or Unread

This commit is contained in:
Rajarshee Chatterjee
2024-07-13 20:09:49 +05:30
parent 9d6e407c40
commit 03e3816ab8
2 changed files with 32 additions and 5 deletions
+22
View File
@@ -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 = ?';
+10 -5
View File
@@ -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,