fix: 两个输入框分支状态完全独立
This commit is contained in:
parent
0d5ad0068a
commit
503eea778b
@ -16,12 +16,19 @@ export default function ReposView() {
|
||||
const [latestBranch, setLatestBranch] = useState('')
|
||||
const [showBranchPicker, setShowBranchPicker] = useState(false)
|
||||
const [scanningBranches, setScanningBranches] = useState(false)
|
||||
const [branchDetected, setBranchDetected] = useState(false)
|
||||
const [apiKey, setApiKey] = useState('')
|
||||
const [expandedRepo, setExpandedRepo] = useState<string | null>(null)
|
||||
const [currentTaskId, setCurrentTaskId] = useState<string | null>(null)
|
||||
const [actionLabel, setActionLabel] = useState('')
|
||||
const [feUrl, setFeUrl] = useState('')
|
||||
const [feBranch, setFeBranch] = useState('main')
|
||||
const [feBranchSuggestions, setFeBranchSuggestions] = useState<{name:string;commit:string}[]>([])
|
||||
const [feBranchCount, setFeBranchCount] = useState(0)
|
||||
const [feLatestBranch, setFeLatestBranch] = useState('')
|
||||
const [feShowBranchPicker, setFeShowBranchPicker] = useState(false)
|
||||
const [feScanningBranches, setFeScanningBranches] = useState(false)
|
||||
const [feBranchDetected, setFeBranchDetected] = useState(false)
|
||||
const [feApiKey, setFeApiKey] = useState('')
|
||||
const [feTaskId, setFeTaskId] = useState<string | null>(null)
|
||||
const [feRunning, setFeRunning] = useState(false)
|
||||
@ -60,12 +67,34 @@ export default function ReposView() {
|
||||
const selected = data.latest && data.latest !== data.default ? data.latest : data.default
|
||||
setBranch(selected || 'main')
|
||||
setLatestBranch(data.latest || '')
|
||||
setBranchDetected(true)
|
||||
setShowBranchPicker(true)
|
||||
}
|
||||
} catch { setBranchSuggestions([{name:'main',commit:''}, {name:'master',commit:''}]) }
|
||||
setScanningBranches(false)
|
||||
}
|
||||
|
||||
const detectFeBranches = async (repoUrl: string) => {
|
||||
if (!repoUrl || !repoUrl.includes('://')) return
|
||||
setFeScanningBranches(true)
|
||||
setFeBranchSuggestions([])
|
||||
setFeBranchCount(0)
|
||||
try {
|
||||
const res = await fetch('/api/repos/branches?url=' + encodeURIComponent(repoUrl))
|
||||
const data = await res.json()
|
||||
if (data.branches && data.branches.length > 0) {
|
||||
setFeBranchSuggestions(data.branches)
|
||||
setFeBranchCount(data.total || 0)
|
||||
const selected = data.latest && data.latest !== data.default ? data.latest : data.default
|
||||
setFeBranch(selected || 'main')
|
||||
setFeLatestBranch(data.latest || '')
|
||||
setFeBranchDetected(true)
|
||||
setFeShowBranchPicker(true)
|
||||
}
|
||||
} catch { setFeBranchSuggestions([{name:'main',commit:''}, {name:'master',commit:''}]) }
|
||||
setFeScanningBranches(false)
|
||||
}
|
||||
|
||||
const scanRepo = async () => {
|
||||
if (!url) return; setActionLabel('扫描仓库')
|
||||
const res = await fetch('/api/repos', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url, branch, api_key: apiKey }) })
|
||||
@ -129,6 +158,13 @@ export default function ReposView() {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{branchDetected && latestBranch && latestBranch !== branch && (
|
||||
<div className="mt-1 text-[10px] flex items-center gap-1" style={{ color: 'rgb(var(--color-success))' }}>
|
||||
<RefreshCw className="w-3 h-3" />
|
||||
已自动选择最新提交分支: <span className="font-medium">{latestBranch}</span>
|
||||
<button className="underline ml-1" onClick={() => setBranch(latestBranch)} style={{ color: 'rgb(var(--color-accent))' }}>切换</button>
|
||||
</div>
|
||||
)}
|
||||
<input type="password" placeholder="API Key *必填" value={apiKey} onChange={e => setApiKey(e.target.value)} className="w-48 px-3 py-2 rounded-lg text-sm outline-none" style={{ backgroundColor: 'rgb(var(--color-page))', borderColor: !apiKey ? 'rgb(var(--color-error))' : 'rgb(var(--color-border))', borderWidth: !apiKey ? '2px' : '1px', color: 'rgb(var(--color-text-primary))' }} />
|
||||
<button onClick={scanRepo} disabled={running || !url || !apiKey} className="flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium bg-[rgb(var(--color-accent))] text-white hover:bg-[rgb(var(--color-accent-hover))] transition-colors disabled:opacity-50" style={{ opacity: running || !url || !apiKey ? 0.5 : 1 }}><Plus className="w-4 h-4" />扫描</button>
|
||||
</div>
|
||||
@ -159,38 +195,45 @@ export default function ReposView() {
|
||||
</div>
|
||||
</div>
|
||||
<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" />
|
||||
<input placeholder="前端仓库 URL" value={feUrl} onChange={e => { setFeUrl(e.target.value); setFeShowBranchPicker(false) }} onBlur={() => { if (feUrl.includes('://')) detectFeBranches(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={() => { if (feUrl.includes('://')) detectBranches(feUrl); 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('://')) detectFeBranches(feUrl); setFeShowBranchPicker(!feShowBranchPicker) }}>
|
||||
<GitBranch className="w-3.5 h-3.5 text-[rgb(var(--color-text-secondary))] shrink-0" />
|
||||
{scanningBranches ? (
|
||||
{feScanningBranches ? (
|
||||
<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' }} />
|
||||
<ChevronDown className="w-3 h-3 text-[rgb(var(--color-text-secondary))] shrink-0 transition-transform" style={{ transform: feShowBranchPicker ? 'rotate(180deg)' : 'none' }} />
|
||||
</div>
|
||||
{showBranchPicker && (
|
||||
{feShowBranchPicker && (
|
||||
<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))' }}>
|
||||
{scanningBranches ? (
|
||||
{feScanningBranches ? (
|
||||
<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 => (
|
||||
feBranchSuggestions.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) }}
|
||||
onClick={() => { setFeBranch(b.name); setFeShowBranchPicker(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>}
|
||||
{b.name === feLatestBranch && <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>
|
||||
{feBranchDetected && feLatestBranch && feLatestBranch !== feBranch && (
|
||||
<div className="mt-1 text-[10px] flex items-center gap-1" style={{ color: 'rgb(var(--color-success))' }}>
|
||||
<RefreshCw className="w-3 h-3" />
|
||||
最新提交分支: <span className="font-medium">{feLatestBranch}</span>
|
||||
<button className="underline ml-1" onClick={() => setFeBranch(feLatestBranch)} style={{ color: 'rgb(var(--color-accent))' }}>切换</button>
|
||||
</div>
|
||||
)}
|
||||
<input type="password" placeholder="API Key *必填" value={feApiKey} onChange={e => setFeApiKey(e.target.value)} className="w-48 px-3 py-2 rounded-lg text-sm outline-none" style={{ backgroundColor: 'rgb(var(--color-page))', borderColor: !feApiKey ? 'rgb(var(--color-error))' : 'rgb(var(--color-border))', borderWidth: !feApiKey ? '2px' : '1px', color: 'rgb(var(--color-text-primary))' }} />
|
||||
<button onClick={async () => {
|
||||
if (!feUrl) return
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user