[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/update pages #1048

Merged
merged 3 commits into from
Apr 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
no hasUpdate in novel page
  • Loading branch information
nyagami committed Apr 26, 2024
commit 83aef1639a08691404ca958f5d6790b20111a0e4
24 changes: 2 additions & 22 deletions src/hooks/persisted/useNovel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SearchResult, UserListEntry } from '@services/Trackers';
import { useMMKVNumber, useMMKVObject } from 'react-native-mmkv';
import { TrackerMetadata, getTracker } from './useTracker';
import { ChapterInfo, NovelInfo } from '@database/types';
import { MMKVStorage, getMMKVObject, setMMKVObject } from '@utils/mmkv/mmkv';
import { MMKVStorage } from '@utils/mmkv/mmkv';
import {
getNovel as _getNovel,
deleteCachedNovels as _deleteCachedNovels,
Expand Down Expand Up @@ -37,7 +37,6 @@ import { parseChapterNumber } from '@utils/parseChapterNumber';
export const TRACKED_NOVEL_PREFIX = 'TRACKED_NOVEL_PREFIX';

export const NOVEL_PAGE_INDEX_PREFIX = 'NOVEL_PAGE_INDEX_PREFIX';
export const NOVEL_PAGE_UPDATES_PREFIX = 'NOVEL_PAGES_UPDATES_PREFIX';
export const NOVEL_SETTINSG_PREFIX = 'NOVEL_SETTINGS';
export const LAST_READ_PREFIX = 'LAST_READ_PREFIX';

Expand Down Expand Up @@ -330,20 +329,6 @@ export const useNovel = (novelPath: string, pluginId: string) => {
pages = Array(novel.totalPages)
.fill(0)
.map((v, idx) => String(idx + 1));
const key = `${NOVEL_PAGE_UPDATES_PREFIX}_${novel.id}`;
const hasUpdates = getMMKVObject<boolean[]>(key);
if (hasUpdates) {
if (pages.length > hasUpdates.length) {
setMMKVObject(
key,
hasUpdates.concat(
Array(pages.length - hasUpdates.length).fill(false),
),
);
}
} else {
setMMKVObject(key, Array(novel.totalPages).fill(false));
}
} else {
pages = (await getCustomPages(novel.id)).map(c => c.page);
}
Expand All @@ -358,15 +343,13 @@ export const useNovel = (novelPath: string, pluginId: string) => {
const getChapters = useCallback(async () => {
const page = pages[pageIndex];
if (novel && page) {
const hasUpdatesKey = `${NOVEL_PAGE_UPDATES_PREFIX}_${novel.id}`;
const hasUpdates = getMMKVObject<boolean[]>(hasUpdatesKey);
let chapters = await _getPageChapters(
novel.id,
novelSettings.sort,
novelSettings.filter,
page,
);
if (hasUpdates && (hasUpdates[pageIndex] || !chapters.length)) {
if (!chapters.length) {
const sourcePage = await fetchPage(pluginId, novelPath, page);
const sourceChapters = sourcePage.chapters.map(ch => {
return {
Expand All @@ -375,8 +358,6 @@ export const useNovel = (novelPath: string, pluginId: string) => {
};
});
await insertChapters(novel.id, sourceChapters);
hasUpdates[pageIndex] = false;
setMMKVObject(hasUpdatesKey, hasUpdates);
chapters = await _getPageChapters(
novel.id,
novelSettings.sort,
Expand Down Expand Up @@ -427,7 +408,6 @@ export const deleteCachedNovels = async () => {
const cachedNovels = await _getCachedNovels();
for (let novel of cachedNovels) {
MMKVStorage.delete(`${TRACKED_NOVEL_PREFIX}_${novel.id}`);
MMKVStorage.delete(`${NOVEL_PAGE_UPDATES_PREFIX}_${novel.id}`);
MMKVStorage.delete(
`${NOVEL_PAGE_INDEX_PREFIX}_${novel.pluginId}_${novel.path}`,
);
Expand Down
Loading