mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 06:25:41 +00:00
d912c4293b
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { create } from 'zustand';
|
|
import type { ServerProfile } from './authStore';
|
|
|
|
let _resolve: ((server: ServerProfile | null) => void) | null = null;
|
|
|
|
interface OrbitAccountPickerStore {
|
|
isOpen: boolean;
|
|
accounts: ServerProfile[];
|
|
/** Open the picker with the given candidates. Resolves with the chosen
|
|
* server or null if the user cancels. */
|
|
request: (accounts: ServerProfile[]) => Promise<ServerProfile | null>;
|
|
pick: (server: ServerProfile) => void;
|
|
cancel: () => void;
|
|
}
|
|
|
|
export const useOrbitAccountPickerStore = create<OrbitAccountPickerStore>(set => ({
|
|
isOpen: false,
|
|
accounts: [],
|
|
|
|
request: (accounts) =>
|
|
new Promise<ServerProfile | null>(resolve => {
|
|
// If another picker is already pending, treat the previous one as cancelled.
|
|
if (_resolve) _resolve(null);
|
|
_resolve = resolve;
|
|
set({ isOpen: true, accounts });
|
|
}),
|
|
|
|
pick: (server) => {
|
|
_resolve?.(server);
|
|
_resolve = null;
|
|
set({ isOpen: false });
|
|
},
|
|
|
|
cancel: () => {
|
|
_resolve?.(null);
|
|
_resolve = null;
|
|
set({ isOpen: false });
|
|
},
|
|
}));
|