mirror of
https://github.com/austinried/subtracks.git
synced 2026-02-10 15:02:42 +01:00
FEATURE: add plain text password toggle to settings (#22)
* FEATURE: add plain text password toggle to settings * clean up state types, lint, and add migrate Co-authored-by: austinried <4966622+austinried@users.noreply.github.com>
This commit is contained in:
@@ -4,10 +4,13 @@ import AsyncStorage from '@react-native-async-storage/async-storage'
|
||||
import create from 'zustand'
|
||||
import { persist, StateStorage } from 'zustand/middleware'
|
||||
import { CacheSlice, createCacheSlice } from './cache'
|
||||
import migrations from './migrations'
|
||||
import { createMusicMapSlice, MusicMapSlice } from './musicmap'
|
||||
import { createTrackPlayerSlice, TrackPlayerSlice } from './trackplayer'
|
||||
import { createTrackPlayerMapSlice, TrackPlayerMapSlice } from './trackplayermap'
|
||||
|
||||
const DB_VERSION = migrations.length
|
||||
|
||||
export type Store = SettingsSlice &
|
||||
MusicSlice &
|
||||
MusicMapSlice &
|
||||
@@ -51,6 +54,7 @@ export const useStore = create<Store>(
|
||||
}),
|
||||
{
|
||||
name: '@appStore',
|
||||
version: DB_VERSION,
|
||||
getStorage: () => storage,
|
||||
whitelist: ['settings', 'cacheFiles'],
|
||||
onRehydrateStorage: _preState => {
|
||||
@@ -59,6 +63,17 @@ export const useStore = create<Store>(
|
||||
postState?.setHydrated(true)
|
||||
}
|
||||
},
|
||||
migrate: (persistedState, version) => {
|
||||
if (version > DB_VERSION) {
|
||||
throw new Error('cannot migrate db on a downgrade, delete all data first')
|
||||
}
|
||||
|
||||
for (let i = version; i < DB_VERSION; i++) {
|
||||
persistedState = migrations[i](persistedState)
|
||||
}
|
||||
|
||||
return persistedState
|
||||
},
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user