feat: list and reorder logged-in accounts in settings #282

This commit is contained in:
Linus Rath
2026-05-20 19:22:44 +02:00
parent ba90ec1f7a
commit d45c8ef511
5 changed files with 379 additions and 62 deletions
+18
View File
@@ -43,6 +43,7 @@ interface AccountState {
setDefaultAccount: (accountId: string) => void;
getDefaultAccount: () => AccountEntry | null;
updateAccount: (accountId: string, updates: Partial<AccountEntry>) => void;
reorderAccounts: (orderedIds: string[]) => void;
getActiveAccount: () => AccountEntry | null;
getAccountById: (accountId: string) => AccountEntry | undefined;
getNextCookieSlot: () => number;
@@ -168,6 +169,23 @@ export const useAccountStore = create<AccountState>()(
}));
},
reorderAccounts: (orderedIds) => {
set((s) => {
const byId = new Map(s.accounts.map((a) => [a.id, a]));
const reordered: AccountEntry[] = [];
for (const id of orderedIds) {
const a = byId.get(id);
if (a) {
reordered.push(a);
byId.delete(id);
}
}
// Append any accounts that weren't in the ordered list (defensive)
for (const a of byId.values()) reordered.push(a);
return { accounts: reordered };
});
},
getActiveAccount: () => {
const state = get();
return state.accounts.find((a) => a.id === state.activeAccountId) ?? null;