port over astra desktop tag algos

This commit is contained in:
Boof2015
2026-06-14 14:57:25 -04:00
parent 51b733a293
commit be740c2d60
9 changed files with 415 additions and 20 deletions
+41
View File
@@ -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);
},
}));