fix: UI修复分支选择器同步加载动画

This commit is contained in:
jiawei.chen 2026-07-08 16:54:06 +08:00
parent 0970fc20b6
commit 0d5ad0068a

View File

@ -161,22 +161,33 @@ export default function ReposView() {
<div className="flex gap-3">
<input placeholder="前端仓库 URL" value={feUrl} onChange={e => { setFeUrl(e.target.value); setShowBranchPicker(false) }} onBlur={() => { if (feUrl.includes('://')) detectBranches(feUrl) }} className="flex-1 px-3 py-2 rounded-lg text-sm bg-[rgb(var(--color-page))] border border-[rgb(var(--color-border))] text-[rgb(var(--color-text-primary))] outline-none" />
<div className="relative w-40">
<div className="flex items-center gap-1 px-3 py-2 rounded-lg text-sm bg-[rgb(var(--color-page))] border border-[rgb(var(--color-border))] text-[rgb(var(--color-text-primary))] cursor-pointer" onClick={() => setShowBranchPicker(!showBranchPicker)}>
<div className="flex items-center gap-1 px-3 py-2 rounded-lg text-sm bg-[rgb(var(--color-page))] border border-[rgb(var(--color-border))] text-[rgb(var(--color-text-primary))] cursor-pointer" onClick={() => { if (feUrl.includes('://')) detectBranches(feUrl); setShowBranchPicker(!showBranchPicker) }}>
<GitBranch className="w-3.5 h-3.5 text-[rgb(var(--color-text-secondary))] shrink-0" />
<span className="flex-1 truncate">{feBranch}</span>
{scanningBranches ? (
<span className="flex-1 text-xs text-[rgb(var(--color-text-secondary))]">扫描中...</span>
) : (
<span className="flex-1 truncate">{feBranch}</span>
)}
<ChevronDown className="w-3 h-3 text-[rgb(var(--color-text-secondary))] shrink-0 transition-transform" style={{ transform: showBranchPicker ? 'rotate(180deg)' : 'none' }} />
</div>
{showBranchPicker && branchSuggestions.length > 0 && (
{showBranchPicker && (
<div className="absolute top-full left-0 right-0 mt-1 rounded-lg border shadow-lg z-50 overflow-hidden max-h-48 overflow-y-auto" style={{ backgroundColor: 'rgb(var(--color-surface))', borderColor: 'rgb(var(--color-border))' }}>
{branchSuggestions.map(b => (
<button key={b.name} className="w-full text-left px-3 py-2 text-xs transition-colors flex items-center gap-2" style={{ color: b.name === feBranch ? 'rgb(var(--color-accent))' : 'rgb(var(--color-text-secondary))', backgroundColor: b.name === feBranch ? 'rgb(var(--color-accent)/0.1)' : 'transparent' }}
onClick={() => { setFeBranch(b.name); setShowBranchPicker(false) }}
onMouseEnter={e => { if (b.name !== feBranch) e.currentTarget.style.backgroundColor = 'rgb(var(--color-surface-hover))' }}
onMouseLeave={e => { if (b.name !== feBranch) e.currentTarget.style.backgroundColor = 'transparent' }}>
<GitBranch className="w-3 h-3 shrink-0" />{b.name}
{b.name === latestBranch && <span className="text-[10px] px-1 py-0.5 rounded ml-auto" style={{ backgroundColor: 'rgb(var(--color-success)/0.15)', color: 'rgb(var(--color-success))' }}>最新</span>}
</button>
))}
{scanningBranches ? (
<div className="px-3 py-4 text-center text-xs text-[rgb(var(--color-text-secondary))]">
<RefreshCw className="w-4 h-4 mx-auto mb-1 animate-spin" />
正在扫描远程分支...
</div>
) : (
branchSuggestions.map(b => (
<button key={b.name} className="w-full text-left px-3 py-2 text-xs transition-colors flex items-center gap-2" style={{ color: b.name === feBranch ? 'rgb(var(--color-accent))' : 'rgb(var(--color-text-secondary))', backgroundColor: b.name === feBranch ? 'rgb(var(--color-accent)/0.1)' : 'transparent' }}
onClick={() => { setFeBranch(b.name); setShowBranchPicker(false) }}
onMouseEnter={e => { if (b.name !== feBranch) e.currentTarget.style.backgroundColor = 'rgb(var(--color-surface-hover))' }}
onMouseLeave={e => { if (b.name !== feBranch) e.currentTarget.style.backgroundColor = 'transparent' }}>
<GitBranch className="w-3 h-3 shrink-0" />{b.name}
{b.name === latestBranch && <span className="text-[10px] px-1 py-0.5 rounded ml-auto" style={{ backgroundColor: 'rgb(var(--color-success)/0.15)', color: 'rgb(var(--color-success))' }}>最新</span>}
</button>
))
)}
</div>
)}
</div>