mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
refactor(auth): E.46 — extract logic-bearing factories (#611)
Three factories for the actions that carry real logic (not just
`set({ field: v })` pass-through):
- `createSkipStarActions` — skip-to-1★ counter with threshold check
and per-`<activeServerId><trackId>` storage key. Disabling the
feature wipes the counter map so a re-enable doesn't resume from
stale partial counts. Crossing the threshold deletes the key so
the next session starts fresh.
- `createMusicLibraryActions` — `setMusicFolders` falls back to
`'all'` when the persisted filter points at a folder the server
no longer reports; `setMusicLibraryFilter` bumps
`musicLibraryFilterVersion` so subscribed pages refetch.
- `createPerServerCapabilityActions` — `setEntityRatingSupport`,
`setAudiomuseNavidromeEnabled`, `setSubsonicServerIdentity`,
`setInstantMixProbe`, `setAudiomuseNavidromeIssue`. Each branch
knows which neighbouring per-server maps to wipe when the input
invalidates them (identity not AudioMuse-eligible / probe empty /
audiomuse disabled).
Pure code-move. authStore.ts: 384 → 270 LOC (−114). All trivial-setter
and logic-bearing action bodies are now out of the store body; only
the persist config + `onRehydrateStorage` migration block remains as
a non-factory chunk (target for E.47).
This commit is contained in:
committed by
GitHub
parent
fe6acdaa4c
commit
2c0aef9538
@@ -0,0 +1,47 @@
|
||||
import type { AuthState } from './authStoreTypes';
|
||||
|
||||
type SetState = (
|
||||
partial: Partial<AuthState> | ((state: AuthState) => Partial<AuthState>),
|
||||
) => void;
|
||||
type GetState = () => AuthState;
|
||||
|
||||
/**
|
||||
* Per-server music-folder selection. `setMusicFolders` is called
|
||||
* after login / server change with the fresh Subsonic folder list;
|
||||
* if the currently-persisted filter for that server points at a
|
||||
* folder that no longer exists on the server, it falls back to
|
||||
* `'all'` so the page doesn't end up filtering by a stale id.
|
||||
*
|
||||
* `setMusicLibraryFilter` writes the new filter and bumps
|
||||
* `musicLibraryFilterVersion` so subscribed pages refetch their
|
||||
* catalog data.
|
||||
*/
|
||||
export function createMusicLibraryActions(set: SetState, get: GetState): Pick<
|
||||
AuthState,
|
||||
'setMusicFolders' | 'setMusicLibraryFilter'
|
||||
> {
|
||||
return {
|
||||
setMusicFolders: (folders) => {
|
||||
const sid = get().activeServerId;
|
||||
set(s => {
|
||||
const f = sid ? s.musicLibraryFilterByServer[sid] : undefined;
|
||||
const invalidFilter = f && f !== 'all' && !folders.some(x => x.id === f);
|
||||
return {
|
||||
musicFolders: folders,
|
||||
...(sid && invalidFilter
|
||||
? { musicLibraryFilterByServer: { ...s.musicLibraryFilterByServer, [sid]: 'all' } }
|
||||
: {}),
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
setMusicLibraryFilter: (folderId) => {
|
||||
const sid = get().activeServerId;
|
||||
if (!sid) return;
|
||||
set(s => ({
|
||||
musicLibraryFilterByServer: { ...s.musicLibraryFilterByServer, [sid]: folderId },
|
||||
musicLibraryFilterVersion: s.musicLibraryFilterVersion + 1,
|
||||
}));
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user