chore(orbit): picker modal when multiple accounts match the link's server

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Psychotoxical
2026-04-24 18:49:55 +02:00
parent 6370b5fa3c
commit d912c4293b
8 changed files with 201 additions and 11 deletions
+39
View File
@@ -0,0 +1,39 @@
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 });
},
}));