mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-20 12:40:15 +02:00
performance improvements + oscilloscope
This commit is contained in:
@@ -9,27 +9,45 @@ import type { ArtistGroupingMode } from '@/library/artistGrouping';
|
||||
* subscribes here to recompute the artist list when the grouping mode changes.
|
||||
*/
|
||||
const ARTIST_GROUPING_KEY = 'artist_grouping_mode';
|
||||
const SCOPE_MODE_KEY = 'scope_mode';
|
||||
|
||||
/** Which visualizer the now-playing scope stage shows. */
|
||||
export type ScopeMode = 'spectrum' | 'scope';
|
||||
|
||||
function parseGroupingMode(value: string | null): ArtistGroupingMode {
|
||||
return value === 'fileTags' ? 'fileTags' : 'astra';
|
||||
}
|
||||
|
||||
function parseScopeMode(value: string | null): ScopeMode {
|
||||
return value === 'scope' ? 'scope' : 'spectrum';
|
||||
}
|
||||
|
||||
interface SettingsStore {
|
||||
artistGroupingMode: ArtistGroupingMode;
|
||||
scopeMode: ScopeMode;
|
||||
loaded: boolean;
|
||||
load: () => Promise<void>;
|
||||
setArtistGroupingMode: (mode: ArtistGroupingMode) => Promise<void>;
|
||||
setScopeMode: (mode: ScopeMode) => Promise<void>;
|
||||
}
|
||||
|
||||
export const useSettingsStore = create<SettingsStore>((set, get) => ({
|
||||
artistGroupingMode: 'astra',
|
||||
scopeMode: 'spectrum',
|
||||
loaded: false,
|
||||
|
||||
load: async () => {
|
||||
if (get().loaded) return;
|
||||
const db = await openLibraryDb();
|
||||
const stored = await getSetting(db, ARTIST_GROUPING_KEY);
|
||||
set({ artistGroupingMode: parseGroupingMode(stored), loaded: true });
|
||||
const [grouping, scope] = await Promise.all([
|
||||
getSetting(db, ARTIST_GROUPING_KEY),
|
||||
getSetting(db, SCOPE_MODE_KEY),
|
||||
]);
|
||||
set({
|
||||
artistGroupingMode: parseGroupingMode(grouping),
|
||||
scopeMode: parseScopeMode(scope),
|
||||
loaded: true,
|
||||
});
|
||||
},
|
||||
|
||||
setArtistGroupingMode: async (mode) => {
|
||||
@@ -38,4 +56,11 @@ export const useSettingsStore = create<SettingsStore>((set, get) => ({
|
||||
const db = await openLibraryDb();
|
||||
await setSetting(db, ARTIST_GROUPING_KEY, mode);
|
||||
},
|
||||
|
||||
setScopeMode: async (mode) => {
|
||||
if (get().scopeMode === mode) return;
|
||||
set({ scopeMode: mode });
|
||||
const db = await openLibraryDb();
|
||||
await setSetting(db, SCOPE_MODE_KEY, mode);
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user