refactor api controller to internalize server fetch

This commit is contained in:
jeffvli
2025-11-02 21:56:35 -08:00
parent 8dbaec3943
commit c7a473d864
79 changed files with 904 additions and 399 deletions
+25 -8
View File
@@ -2,27 +2,28 @@ import merge from 'lodash/merge';
import { nanoid } from 'nanoid/non-secure';
import { devtools, persist } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
import { shallow } from 'zustand/shallow';
import { createWithEqualityFn } from 'zustand/traditional';
import { useAlbumArtistListDataStore } from '/@/renderer/store/album-artist-list-data.store';
import { useAlbumListDataStore } from '/@/renderer/store/album-list-data.store';
import { useListStore } from '/@/renderer/store/list.store';
import { ServerListItem } from '/@/shared/types/domain-types';
import { ServerListItem, ServerListItemWithCredential } from '/@/shared/types/domain-types';
export interface AuthSlice extends AuthState {
actions: {
addServer: (args: ServerListItem) => void;
addServer: (args: ServerListItemWithCredential) => void;
deleteServer: (id: string) => void;
getServer: (id: string) => null | ServerListItem;
setCurrentServer: (server: null | ServerListItem) => void;
updateServer: (id: string, args: Partial<ServerListItem>) => void;
getServer: (id: string) => null | ServerListItemWithCredential;
setCurrentServer: (server: null | ServerListItemWithCredential) => void;
updateServer: (id: string, args: Partial<ServerListItemWithCredential>) => void;
};
}
export interface AuthState {
currentServer: null | ServerListItem;
currentServer: null | ServerListItemWithCredential;
deviceId: string;
serverList: Record<string, ServerListItem>;
serverList: Record<string, ServerListItemWithCredential>;
}
export const useAuthStore = createWithEqualityFn<AuthSlice>()(
@@ -92,7 +93,23 @@ export const useAuthStore = createWithEqualityFn<AuthSlice>()(
export const useCurrentServerId = () => useAuthStore((state) => state.currentServer)?.id || '';
export const useCurrentServer = () =>
useAuthStore((state) => state.currentServer) as ServerListItem;
useAuthStore((state) => {
return {
features: state.currentServer?.features,
id: state.currentServer?.id,
name: state.currentServer?.name,
preferInstantMix: state.currentServer?.preferInstantMix,
savePassword: state.currentServer?.savePassword,
type: state.currentServer?.type,
url: state.currentServer?.url,
userId: state.currentServer?.userId,
username: state.currentServer?.username,
version: state.currentServer?.version,
};
}, shallow) as ServerListItem;
export const useCurrentServerWithCredential = () =>
useAuthStore((state) => state.currentServer) as ServerListItemWithCredential;
export const useServerList = () => useAuthStore((state) => state.serverList);
-1
View File
@@ -914,7 +914,6 @@ export const useSettingsStore = createWithEqualityFn<SettingsSlice>()(
merge: mergeOverridingColumns,
migrate(persistedState, version) {
const state = persistedState as SettingsSlice;
console.log('migrate: ', version);
if (version === 8) {
state.general.sidebarItems = state.general.sidebarItems.filter(