Skip to content

Commit 894e8bb

Browse files
committed
mmkv not persisting
1 parent 8bf2af9 commit 894e8bb

12 files changed

Lines changed: 63 additions & 30 deletions

File tree

metro.config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
// Learn more https://docs.expo.io/guides/customizing-metro
1+
const { getDefaultConfig } = require('expo/metro-config');
2+
const { mergeConfig } = require('@react-native/metro-config');
23

34
/**
45
* Metro configuration
56
* https://reactnative.dev/docs/metro
67
*
7-
* @type {import('@react-native/metro-config').MetroConfig}
8+
* @type {import('expo/metro-config').MetroConfig}
89
*/
9-
1010
const path = require('path');
1111
const fs = require('fs');
12-
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
1312
const defaultConfig = getDefaultConfig(__dirname);
1413

1514
const map = {

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@op-engineering/op-sqlite": "^15.2.7",
5555
"@preeternal/react-native-cookie-manager": "^6.3.1",
5656
"@react-native-community/slider": "^5.1.2",
57-
"@react-native-documents/picker": "^10.1.7",
57+
"@react-native-documents/picker": "^12.0.0",
5858
"@react-native-google-signin/google-signin": "^16.1.2",
5959
"@react-native-vector-icons/common": "^12.4.2",
6060
"@react-native-vector-icons/material-design-icons": "^12.5.0",
@@ -100,7 +100,8 @@
100100
"react-native-file-access": "^4.0.1",
101101
"react-native-gesture-handler": "^2.30.1",
102102
"react-native-lottie-splash-screen": "^1.1.2",
103-
"react-native-mmkv": "^3.3.3",
103+
"react-native-mmkv": "^4.3.0",
104+
"react-native-nitro-modules": "^0.35.2",
104105
"react-native-pager-view": "^8.0.0",
105106
"react-native-paper": "^5.15.0",
106107
"react-native-reanimated": "^4.3.0",
@@ -124,6 +125,7 @@
124125
"@react-native-community/cli": "^20.1.3",
125126
"@react-native-community/cli-platform-android": "^20.1.3",
126127
"@react-native-community/cli-platform-ios": "^20.1.3",
128+
"@react-native/assets-registry": "^0.83.4",
127129
"@react-native/babel-preset": "^0.83.4",
128130
"@react-native/eslint-config": "^0.83.4",
129131
"@react-native/eslint-plugin": "^0.83.4",

pnpm-lock.yaml

Lines changed: 30 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hooks/__tests__/useNovel.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ describe('useNovel', () => {
7878
beforeEach(() => {
7979
jest.clearAllMocks();
8080
MMKVStorage.clearAll();
81+
console.log('--- Starting test ---');
8182
// Default happy-path mocks
8283
(getNovelByPath as jest.Mock).mockReturnValue(mockNovel);
8384
(getChapterCount as jest.Mock).mockResolvedValue(mockChapters.length);

src/hooks/persisted/useNovel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,14 +675,14 @@ export const useNovel = (novelOrPath: string | NovelInfo, pluginId: string) => {
675675
export const deleteCachedNovels = async () => {
676676
const cachedNovels = await _getCachedNovels();
677677
for (const novel of cachedNovels) {
678-
MMKVStorage.delete(`${TRACKED_NOVEL_PREFIX}_${novel.id}`);
679-
MMKVStorage.delete(
678+
MMKVStorage.remove(`${TRACKED_NOVEL_PREFIX}_${novel.id}`);
679+
MMKVStorage.remove(
680680
`${NOVEL_PAGE_INDEX_PREFIX}_${novel.pluginId}_${novel.path}`,
681681
);
682-
MMKVStorage.delete(
682+
MMKVStorage.remove(
683683
`${NOVEL_SETTINGS_PREFIX}_${novel.pluginId}_${novel.path}`,
684684
);
685-
MMKVStorage.delete(`${LAST_READ_PREFIX}_${novel.pluginId}_${novel.path}`);
685+
MMKVStorage.remove(`${LAST_READ_PREFIX}_${novel.pluginId}_${novel.path}`);
686686
const novelDir = NOVEL_STORAGE + '/' + novel.pluginId + '/' + novel.id;
687687
if (NativeFile.exists(novelDir)) {
688688
NativeFile.unlink(novelDir);

src/hooks/persisted/usePlugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default function usePlugins() {
132132

133133
const uninstallPlugin = (plugin: PluginItem) => {
134134
if (lastUsedPlugin?.id === plugin.id) {
135-
MMKVStorage.delete(LAST_USED_PLUGIN);
135+
MMKVStorage.remove(LAST_USED_PLUGIN);
136136
}
137137
if (pinnedPlugins.includes(plugin.id)) {
138138
setPinnedPlugins(pinnedPlugins.filter(id => id !== plugin.id));

src/hooks/persisted/useTrackedNovel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const useTrackedNovel = (novelId: number | 'NO_ID') => {
4545
const oldData = getMMKVObject<TrackedNovel>(oldKey);
4646

4747
if (oldData) {
48-
MMKVStorage.delete(oldKey);
48+
MMKVStorage.remove(oldKey);
4949
}
5050

5151
setMigrated('true');
@@ -123,7 +123,7 @@ export const useTrackedNovel = (novelId: number | 'NO_ID') => {
123123
}
124124

125125
const key = getTrackerStorageKey(novelId, trackerName);
126-
MMKVStorage.delete(key);
126+
MMKVStorage.remove(key);
127127

128128
setTrackedNovels(prev => {
129129
const newTracked = { ...prev };

src/navigators/Main.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,19 @@ import ServiceManager from '@services/ServiceManager';
3939
import ReaderStack from './ReaderStack';
4040
import { LibraryContextProvider } from '@components/Context/LibraryContext';
4141
import { UpdateContextProvider } from '@components/Context/UpdateContext';
42+
import { MMKVStorage } from '@utils/mmkv/mmkv';
4243
const Stack = createNativeStackNavigator<RootStackParamList>();
4344

4445
const MainNavigator = () => {
4546
const theme = useTheme();
4647
const { updateLibraryOnLaunch } = useAppSettings();
4748
const { refreshPlugins } = usePlugins();
48-
const [isOnboarded] = useMMKVBoolean('IS_ONBOARDED');
49-
49+
const [isOnboarded] = useMMKVBoolean('IS_ONBOARDED', MMKVStorage);
50+
console.log(
51+
'MainNavigator rendered, isOnboarded:',
52+
isOnboarded,
53+
MMKVStorage.getAllKeys(),
54+
);
5055
useEffect(() => {
5156
const timer = setTimeout(async () => {
5257
setStatusBarColor(theme);

src/plugins/helpers/storage.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { MMKV } from 'react-native-mmkv';
1+
import { createMMKV } from 'react-native-mmkv';
22

3-
const store = new MMKV({ id: 'plugin_db' });
3+
const store = createMMKV({ id: 'plugin_db' });
44

55
const PLUGIN_STORAGE = '_DB_';
66
const WEBVIEW_LOCAL_STORAGE = '_LocalStorage';
@@ -73,6 +73,7 @@ class Storage {
7373
* Clears all stored items from storage.
7474
*/
7575
clearAll(): void {
76+
consoele.log('Clearing all plugin storage for pluginID:', this.#pluginID);
7677
const keysToRemove = this.getAllKeys();
7778
keysToRemove.forEach(key => this.delete(key));
7879
}

src/screens/onboarding/OnboardingScreen.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ export default function OnboardingScreen() {
6262
title={getString('onboardingScreen.complete')}
6363
mode="contained"
6464
onPress={() => {
65+
console.log(
66+
'complete onboarding',
67+
MMKVStorage.getAllKeys(),
68+
MMKVStorage.getBoolean('IS_ONBOARDED'),
69+
);
6570
MMKVStorage.set('IS_ONBOARDED', true);
6671
}}
6772
/>

0 commit comments

Comments
 (0)