mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-20 04:30:54 +02:00
port over astra desktop tag algos
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { create } from 'zustand';
|
||||
import { openLibraryDb } from '@/db/database';
|
||||
import { getSetting, setSetting } from '@/db/queries';
|
||||
import type { ArtistGroupingMode } from '@/library/artistGrouping';
|
||||
|
||||
/**
|
||||
* Persisted app preferences. SQLite (settings table) is the source of truth — this
|
||||
* store mirrors it in memory. Kept free of cross-store imports; libraryStore
|
||||
* subscribes here to recompute the artist list when the grouping mode changes.
|
||||
*/
|
||||
const ARTIST_GROUPING_KEY = 'artist_grouping_mode';
|
||||
|
||||
function parseGroupingMode(value: string | null): ArtistGroupingMode {
|
||||
return value === 'fileTags' ? 'fileTags' : 'astra';
|
||||
}
|
||||
|
||||
interface SettingsStore {
|
||||
artistGroupingMode: ArtistGroupingMode;
|
||||
loaded: boolean;
|
||||
load: () => Promise<void>;
|
||||
setArtistGroupingMode: (mode: ArtistGroupingMode) => Promise<void>;
|
||||
}
|
||||
|
||||
export const useSettingsStore = create<SettingsStore>((set, get) => ({
|
||||
artistGroupingMode: 'astra',
|
||||
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 });
|
||||
},
|
||||
|
||||
setArtistGroupingMode: async (mode) => {
|
||||
if (get().artistGroupingMode === mode) return;
|
||||
set({ artistGroupingMode: mode });
|
||||
const db = await openLibraryDb();
|
||||
await setSetting(db, ARTIST_GROUPING_KEY, mode);
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user