@@ -28,7 +28,6 @@ import { useCallback, useEffect, useState } from 'react';
|
||||
import { NovelDownloadFolder } from '@utils/constants/download';
|
||||
import * as RNFS from 'react-native-fs';
|
||||
import { getString } from '@strings/translations';
|
||||
import { ChapterItem } from '@plugins/types';
|
||||
import dayjs from 'dayjs';
|
||||
import { parseChapterNumber } from '@utils/parseChapterNumber';
|
||||
|
||||
@@ -326,6 +325,12 @@ export const useNovel = (novelPath: string, pluginId: string) => {
|
||||
if (!novel) {
|
||||
return;
|
||||
}
|
||||
if (sourceNovel.latestChapter) {
|
||||
setMMKVObject(
|
||||
`${NOVEL_LATEST_CHAPTER_PREFIX}_${novel.id}`,
|
||||
sourceNovel.latestChapter,
|
||||
);
|
||||
}
|
||||
}
|
||||
let pages: string[];
|
||||
if (novel.totalPages > 0) {
|
||||
@@ -377,26 +382,8 @@ export const useNovel = (novelPath: string, pluginId: string) => {
|
||||
};
|
||||
});
|
||||
await insertChapters(novel.id, sourceChapters);
|
||||
const latestChapkey = `${NOVEL_LATEST_CHAPTER_PREFIX}_${novel.id}`;
|
||||
const latestChapter = getMMKVObject<ChapterItem>(latestChapkey);
|
||||
if (
|
||||
sourcePage.latestChapter &&
|
||||
sourcePage.latestChapter.path !== latestChapter?.path
|
||||
) {
|
||||
setMMKVObject(latestChapkey, sourcePage.latestChapter);
|
||||
setMMKVObject(
|
||||
hasUpdatesKey,
|
||||
hasUpdates?.map((val, idx) => {
|
||||
if (idx !== pageIndex) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
hasUpdates[pageIndex] = false;
|
||||
setMMKVObject(hasUpdatesKey, hasUpdates);
|
||||
}
|
||||
hasUpdates[pageIndex] = false;
|
||||
setMMKVObject(hasUpdatesKey, hasUpdates);
|
||||
chapters = await _getPageChapters(
|
||||
novel.id,
|
||||
novelSettings.sort,
|
||||
|
||||
@@ -33,11 +33,11 @@ export interface SourceNovel extends NovelItem {
|
||||
status?: NovelStatus;
|
||||
chapters: ChapterItem[];
|
||||
totalPages?: number;
|
||||
latestChapter?: ChapterItem;
|
||||
}
|
||||
|
||||
export interface SourcePage {
|
||||
chapters: ChapterItem[];
|
||||
latestChapter?: ChapterItem;
|
||||
}
|
||||
|
||||
export interface PopularNovelsOptions<Q extends Filters> {
|
||||
|
||||
@@ -2,12 +2,15 @@ import { fetchImage, fetchNovel } from '../plugin/fetch';
|
||||
import { downloadChapter } from '../../database/queries/ChapterQueries';
|
||||
|
||||
import * as SQLite from 'expo-sqlite';
|
||||
import { SourceNovel } from '@plugins/types';
|
||||
import { ChapterItem, SourceNovel } from '@plugins/types';
|
||||
import { LOCAL_PLUGIN_ID } from '@plugins/pluginManager';
|
||||
import { NovelDownloadFolder } from '@utils/constants/download';
|
||||
import * as RNFS from 'react-native-fs';
|
||||
import { getMMKVObject, setMMKVObject } from '@utils/mmkv/mmkv';
|
||||
import { NOVEL_PAGE_UPDATES_PREFIX } from '@hooks/persisted/useNovel';
|
||||
import {
|
||||
NOVEL_LATEST_CHAPTER_PREFIX,
|
||||
NOVEL_PAGE_UPDATES_PREFIX,
|
||||
} from '@hooks/persisted/useNovel';
|
||||
const db = SQLite.openDatabase('lnreader.db');
|
||||
|
||||
const updateNovelMetadata = (
|
||||
@@ -156,13 +159,17 @@ const updateNovel = async (
|
||||
await updateNovelMetadata(pluginId, novelId, novel);
|
||||
}
|
||||
await updateNovelChapters(pluginId, novelId, novel, downloadNewChapters);
|
||||
const key = `${NOVEL_PAGE_UPDATES_PREFIX}_${novelId}`;
|
||||
const hasUpdates = getMMKVObject<boolean[]>(key);
|
||||
if (hasUpdates) {
|
||||
setMMKVObject(
|
||||
key,
|
||||
hasUpdates.map(() => true),
|
||||
);
|
||||
const latestChapterKey = `${NOVEL_LATEST_CHAPTER_PREFIX}_${novelId}`;
|
||||
const latestChapter = getMMKVObject<ChapterItem>(latestChapterKey);
|
||||
if (novel.latestChapter && novel.latestChapter.path !== latestChapter?.path) {
|
||||
const hasUpdatesKey = `${NOVEL_PAGE_UPDATES_PREFIX}_${novelId}`;
|
||||
const hasUpdates = getMMKVObject<boolean[]>(hasUpdatesKey);
|
||||
if (hasUpdates) {
|
||||
setMMKVObject(
|
||||
hasUpdatesKey,
|
||||
hasUpdates.map(() => true),
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user