Spaces:
Paused
Paused
icebear0828 Claude Sonnet 4.6 commited on
Commit ·
e6a1587
1
Parent(s): 9d65acf
feat: add manual refresh button with timestamp to account list
Browse files- Separate `refreshing` state from initial `loading` so the list stays
visible while re-fetching (no blank flash on refresh)
- Track `lastUpdated` timestamp, shown as "Updated at HH:MM:SS" next to
the button (hidden on mobile, visible sm+)
- Refresh button spins during fetch and is disabled to prevent double-tap
- i18n: add `refresh` / `updatedAt` keys in both en and zh
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Files changed (4)
28 unmodified lines29303132333428 unmodified linesaccounts={accounts.list}loading={accounts.loading}onDelete={accounts.deleteAccount}/><ApiConfigbaseUrl={status.baseUrl}28 unmodified lines29303132333435363728 unmodified linesaccounts={accounts.list}loading={accounts.loading}onDelete={accounts.deleteAccount}onRefresh={accounts.refresh}refreshing={accounts.refreshing}lastUpdated={accounts.lastUpdated}/><ApiConfigbaseUrl={status.baseUrl}
12341 unmodified line67891011121314151617181920212223import { useT } from "../i18n/context";import { AccountCard } from "./AccountCard";import type { Account } from "../hooks/use-accounts";1 unmodified lineaccounts: Account[];loading: boolean;onDelete: (id: string) => Promise<string | null>;}export function AccountList({ accounts, loading, onDelete }: AccountListProps) {const t = useT();return (<section class="flex flex-col gap-4"><div class="flex items-end justify-between"><div class="flex flex-col gap-1"><h2 class="text-[0.95rem] font-bold tracking-tight">{t("connectedAccounts")}</h2><p class="text-slate-500 dark:text-text-dim text-[0.8rem]">{t("connectedAccountsDesc")}</p></div></div><div class="grid grid-cols-1 md:grid-cols-2 gap-4">{loading ? (12341 unmodified line6789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import { useI18n, useT } from "../i18n/context";import { AccountCard } from "./AccountCard";import type { Account } from "../hooks/use-accounts";1 unmodified lineaccounts: Account[];loading: boolean;onDelete: (id: string) => Promise<string | null>;onRefresh: () => void;refreshing: boolean;lastUpdated: Date | null;}export function AccountList({ accounts, loading, onDelete, onRefresh, refreshing, lastUpdated }: AccountListProps) {const t = useT();const { lang } = useI18n();const updatedAtText = lastUpdated? lastUpdated.toLocaleTimeString(lang === "zh" ? "zh-CN" : "en-US", { hour: "2-digit", minute: "2-digit", second: "2-digit" }): null;return (<section class="flex flex-col gap-4"><div class="flex items-center justify-between"><div class="flex flex-col gap-1"><h2 class="text-[0.95rem] font-bold tracking-tight">{t("connectedAccounts")}</h2><p class="text-slate-500 dark:text-text-dim text-[0.8rem]">{t("connectedAccountsDesc")}</p></div><div class="flex items-center gap-2 shrink-0">{updatedAtText && (<span class="text-[0.75rem] text-slate-400 dark:text-text-dim hidden sm:inline">{t("updatedAt")} {updatedAtText}</span>)}<buttononClick={onRefresh}disabled={refreshing}title={t("refresh")}class="p-1.5 text-slate-400 dark:text-text-dim hover:text-primary transition-colors rounded-md hover:bg-primary/10 disabled:opacity-40 disabled:cursor-not-allowed"><svgclass={`size-[18px] ${refreshing ? "animate-spin" : ""}`}viewBox="0 0 24 24"fill="none"stroke="currentColor"stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99" /></svg></button></div></div><div class="grid grid-cols-1 md:grid-cols-2 gap-4">{loading ? (
23 unmodified lines24252627282930313233343536373839404142103 unmodified lines14614714814915015115215315423 unmodified linesexport function useAccounts() {const [list, setList] = useState<Account[]>([]);const [loading, setLoading] = useState(true);const [addVisible, setAddVisible] = useState(false);const [addInfo, setAddInfo] = useState("");const [addError, setAddError] = useState("");const loadAccounts = useCallback(async () => {try {const resp = await fetch("/auth/accounts?quota=true");const data = await resp.json();setList(data.accounts || []);} catch (err) {setList([]);} finally {setLoading(false);}}, []);103 unmodified linesreturn {list,loading,addVisible,addInfo,addError,startAdd,submitRelay,deleteAccount,23 unmodified lines242526272829303132333435363738394041424344454647103 unmodified lines15115215315415515615715815916016116223 unmodified linesexport function useAccounts() {const [list, setList] = useState<Account[]>([]);const [loading, setLoading] = useState(true);const [refreshing, setRefreshing] = useState(false);const [lastUpdated, setLastUpdated] = useState<Date | null>(null);const [addVisible, setAddVisible] = useState(false);const [addInfo, setAddInfo] = useState("");const [addError, setAddError] = useState("");const loadAccounts = useCallback(async () => {setRefreshing(true);try {const resp = await fetch("/auth/accounts?quota=true");const data = await resp.json();setList(data.accounts || []);setLastUpdated(new Date());} catch {setList([]);} finally {setLoading(false);setRefreshing(false);}}, []);103 unmodified linesreturn {list,loading,refreshing,lastUpdated,addVisible,addInfo,addError,refresh: loadAccounts,startAdd,submitRelay,deleteAccount,
51 unmodified lines52535455565751 unmodified lines10911011111211311451 unmodified linesnetworkError: "Network error: ",copied: "Copied!",copyFailed: "Failed",footer: "\u00a9 2025 Codex Proxy. All rights reserved.",},zh: {51 unmodified linesnetworkError: "\u7f51\u7edc\u9519\u8bef\uff1a",copied: "\u5df2\u590d\u5236\uff01",copyFailed: "\u5931\u8d25",footer:"\u00a9 2025 Codex Proxy\u3002\u4fdd\u7559\u6240\u6709\u6743\u5229\u3002",},51 unmodified lines525354555657585951 unmodified lines11111211311411511611711851 unmodified linesnetworkError: "Network error: ",copied: "Copied!",copyFailed: "Failed",refresh: "Refresh",updatedAt: "Updated at",footer: "\u00a9 2025 Codex Proxy. All rights reserved.",},zh: {51 unmodified linesnetworkError: "\u7f51\u7edc\u9519\u8bef\uff1a",copied: "\u5df2\u590d\u5236\uff01",copyFailed: "\u5931\u8d25",refresh: "\u5237\u65b0",updatedAt: "\u66f4\u65b0\u4e8e",footer:"\u00a9 2025 Codex Proxy\u3002\u4fdd\u7559\u6240\u6709\u6743\u5229\u3002",},
web/src/App.tsx+3
web/src/components/AccountList.tsx+34-3
web/src/hooks/use-accounts.ts+9-1
web/src/i18n/translations.ts+4