fix: clear novel settings when deleting
This commit is contained in:
@@ -14,6 +14,15 @@ import { getString } from '@strings/translations';
|
||||
import { BackupNovel, NovelInfo } from '../types';
|
||||
import { SourceNovel } from '@plugins/types';
|
||||
import { NovelDownloadFolder } from '@utils/constants/download';
|
||||
import { MMKVStorage } from '@utils/mmkv/mmkv';
|
||||
import {
|
||||
LAST_READ_PREFIX,
|
||||
NOVEL_CHAPTERS_PREFIX,
|
||||
NOVEL_PREFIX,
|
||||
NOVEL_SETTINSG_PREFIX,
|
||||
PROGRESS_PREFIX,
|
||||
TRACKED_NOVEL_PREFIX,
|
||||
} from '@hooks/persisted/useNovel';
|
||||
|
||||
export const insertNovelAndChapters = async (
|
||||
pluginId: string,
|
||||
@@ -176,6 +185,12 @@ export const getCachedNovels = (): Promise<NovelInfo[]> => {
|
||||
export const deleteCachedNovels = async () => {
|
||||
const cachedNovels = await getCachedNovels();
|
||||
for (let novel of cachedNovels) {
|
||||
MMKVStorage.delete(TRACKED_NOVEL_PREFIX + '_' + novel.url);
|
||||
MMKVStorage.delete(NOVEL_PREFIX + '_' + novel.url);
|
||||
MMKVStorage.delete(NOVEL_CHAPTERS_PREFIX + '_' + novel.url);
|
||||
MMKVStorage.delete(NOVEL_SETTINSG_PREFIX + '_' + novel.url);
|
||||
MMKVStorage.delete(LAST_READ_PREFIX + '_' + novel.url);
|
||||
MMKVStorage.delete(PROGRESS_PREFIX + '_' + novel.url);
|
||||
const novelDir =
|
||||
NovelDownloadFolder + '/' + novel.pluginId + '/' + novel.id;
|
||||
if (await RNFS.exists(novelDir)) {
|
||||
|
||||
@@ -24,14 +24,13 @@ import { APP_SETTINGS, AppSettings } from './useSettings';
|
||||
import { showToast } from '@utils/showToast';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
// store key: PREFIX + '_' + novel.id,
|
||||
// store key: PREFIX + '_' + novel.url,
|
||||
|
||||
export const TRACKED_NOVEL_PREFIX = 'TRACKED_NOVEL_PREFIX';
|
||||
|
||||
export const NOVEL_PREFIX = 'NOVEL_PREFIX';
|
||||
export const NOVEL_CHAPTERS_PREFIX = 'NOVEL_CHAPTERS_PREFIX';
|
||||
|
||||
export const CURRENT_CHAPTER = 'CURRENT_CHAPTER';
|
||||
export const NOVEL_SETTINSG_PREFIX = 'NOVEL_SETTINGS';
|
||||
export const LAST_READ_PREFIX = 'LAST_READ_PREFIX';
|
||||
export const PROGRESS_PREFIX = 'PROGRESS_PREFIX';
|
||||
@@ -53,9 +52,9 @@ export interface NovelProgress {
|
||||
[chapterId: number]: ChapterProgress;
|
||||
}
|
||||
|
||||
export const useTrackedNovel = (id: number) => {
|
||||
export const useTrackedNovel = (url: string) => {
|
||||
const [trackedNovel, setValue] = useMMKVObject<TrackedNovel>(
|
||||
TRACKED_NOVEL_PREFIX + '_' + id,
|
||||
TRACKED_NOVEL_PREFIX + '_' + url,
|
||||
);
|
||||
|
||||
const trackNovel = (tracker: TrackerMetadata, novel: SearchResult) => {
|
||||
@@ -365,6 +364,3 @@ export const useNovel = (url: string, pluginId: string) => {
|
||||
deleteChapters,
|
||||
};
|
||||
};
|
||||
|
||||
export const getCurrentChapter = () =>
|
||||
getMMKVObject<ChapterInfo>(CURRENT_CHAPTER);
|
||||
|
||||
@@ -686,7 +686,7 @@ const Novel = ({ route, navigation }: NovelScreenProps) => {
|
||||
/>
|
||||
<TrackSheet
|
||||
bottomSheetRef={trackerSheetRef}
|
||||
novelId={novel.id}
|
||||
novelUrl={novel.url}
|
||||
novelName={novel.name}
|
||||
theme={theme}
|
||||
/>
|
||||
|
||||
@@ -29,7 +29,7 @@ const NovelScreenButtonGroup: React.FC<NovelScreenButtonGroupProps> = ({
|
||||
const { navigate } = useNavigation<NovelScreenProps['navigation']>();
|
||||
const followButtonColor = inLibrary ? theme.primary : theme.outline;
|
||||
const { tracker } = useTracker();
|
||||
const { trackedNovel } = useTrackedNovel(novel.id);
|
||||
const { trackedNovel } = useTrackedNovel(novel.url);
|
||||
|
||||
const trackerButtonColor = trackedNovel ? theme.primary : theme.outline;
|
||||
|
||||
|
||||
@@ -15,15 +15,15 @@ import { UserListStatus } from '@services/Trackers';
|
||||
|
||||
interface Props {
|
||||
bottomSheetRef: React.RefObject<BottomSheetModalMethods>;
|
||||
novelId: number;
|
||||
novelUrl: string;
|
||||
novelName: string;
|
||||
theme: ThemeColors;
|
||||
}
|
||||
|
||||
const TrackSheet = ({ bottomSheetRef, novelId, novelName, theme }: Props) => {
|
||||
const TrackSheet = ({ bottomSheetRef, novelUrl, novelName, theme }: Props) => {
|
||||
const { tracker } = useTracker();
|
||||
const { trackedNovel, trackNovel, untrackNovel, updateTrackedNovel } =
|
||||
useTrackedNovel(novelId);
|
||||
useTrackedNovel(novelUrl);
|
||||
|
||||
const [trackSearchDialog, setTrackSearchDialog] = useState(false);
|
||||
const [trackStatusDialog, setTrackStatusDialog] = useState(false);
|
||||
|
||||
@@ -109,7 +109,7 @@ export const ChapterContent = ({
|
||||
const [hidden, setHidden] = useState(true);
|
||||
|
||||
const { tracker } = useTracker();
|
||||
const { trackedNovel, updateNovelProgess } = useTrackedNovel(novel.id);
|
||||
const { trackedNovel, updateNovelProgess } = useTrackedNovel(novel.url);
|
||||
|
||||
const [sourceChapter, setChapter] = useState({ ...chapter, chapterText: '' });
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
Reference in New Issue
Block a user