icebear0828 commited on
Commit
2ee9797
·
1 Parent(s): 3cf831b

perf: instant proxy mode switching via optimistic UI update

Browse files

Replace slow accounts.refresh() (fetches quota from chatgpt.com per account)
with local state patch for immediate UI response.

Files changed (2) hide show
  1. shared/hooks/use-accounts.ts +5 -0
  2. web/src/App.tsx +1 -1
shared/hooks/use-accounts.ts CHANGED
@@ -128,6 +128,10 @@ export function useAccounts() {
128
  [loadAccounts]
129
  );
130
 
 
 
 
 
131
  return {
132
  list,
133
  loading,
@@ -137,6 +141,7 @@ export function useAccounts() {
137
  addInfo,
138
  addError,
139
  refresh: loadAccounts,
 
140
  startAdd,
141
  submitRelay,
142
  deleteAccount,
 
128
  [loadAccounts]
129
  );
130
 
131
+ const patchLocal = useCallback((accountId: string, patch: Partial<Account>) => {
132
+ setList((prev) => prev.map((a) => a.id === accountId ? { ...a, ...patch } : a));
133
+ }, []);
134
+
135
  return {
136
  list,
137
  loading,
 
141
  addInfo,
142
  addError,
143
  refresh: loadAccounts,
144
+ patchLocal,
145
  startAdd,
146
  submitRelay,
147
  deleteAccount,
web/src/App.tsx CHANGED
@@ -62,8 +62,8 @@ function Dashboard() {
62
  const update = useUpdateMessage();
63
 
64
  const handleProxyChange = async (accountId: string, proxyId: string) => {
 
65
  await proxies.assignProxy(accountId, proxyId);
66
- accounts.refresh();
67
  };
68
 
69
  return (
 
62
  const update = useUpdateMessage();
63
 
64
  const handleProxyChange = async (accountId: string, proxyId: string) => {
65
+ accounts.patchLocal(accountId, { proxyId });
66
  await proxies.assignProxy(accountId, proxyId);
 
67
  };
68
 
69
  return (