Add refresh button to Docker widget with server cache bust
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -15,14 +15,20 @@ export function DockerUpdatesWidget() {
|
||||
const [containers, setContainers] = useState<ContainerInfo[]>([])
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [refreshing, setRefreshing] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/updates/docker')
|
||||
const load = (bust = false) => {
|
||||
if (bust) setRefreshing(true)
|
||||
else setLoading(true)
|
||||
setError(null)
|
||||
fetch(`/api/updates/docker${bust ? '?refresh=1' : ''}`)
|
||||
.then(r => r.json())
|
||||
.then(d => { if (d.error) setError(d.error); else setContainers(d.containers) })
|
||||
.catch(() => setError('Failed to connect'))
|
||||
.finally(() => setLoading(false))
|
||||
}, [])
|
||||
.finally(() => { setLoading(false); setRefreshing(false) })
|
||||
}
|
||||
|
||||
useEffect(() => { load() }, [])
|
||||
|
||||
const outdated = containers.filter(c => c.upToDate === false)
|
||||
const upToDate = containers.filter(c => c.upToDate === true)
|
||||
@@ -36,11 +42,26 @@ export function DockerUpdatesWidget() {
|
||||
<div className="card">
|
||||
<div className="widget-header">
|
||||
<div className="widget-title"><span className="dot" />Docker</div>
|
||||
{!loading && !error && (
|
||||
<span className="widget-badge" style={outdated.length > 0 ? { background: 'rgba(248,113,113,0.15)', color: 'var(--red)' } : {}}>
|
||||
{outdated.length > 0 ? `${outdated.length} outdated` : 'all current'}
|
||||
</span>
|
||||
)}
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
{!loading && !error && (
|
||||
<span className="widget-badge" style={outdated.length > 0 ? { background: 'rgba(248,113,113,0.15)', color: 'var(--red)' } : {}}>
|
||||
{outdated.length > 0 ? `${outdated.length} outdated` : 'all current'}
|
||||
</span>
|
||||
)}
|
||||
<button
|
||||
onClick={() => load(true)}
|
||||
disabled={refreshing || loading}
|
||||
title="Re-check all images"
|
||||
style={{
|
||||
background: 'none', border: '1px solid var(--border)', borderRadius: 6,
|
||||
color: 'var(--muted)', cursor: 'pointer', padding: '2px 6px', fontSize: 11,
|
||||
lineHeight: 1, transition: 'color 0.15s',
|
||||
opacity: refreshing || loading ? 0.4 : 1,
|
||||
}}
|
||||
>
|
||||
{refreshing ? '…' : '↺'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{loading && <div className="widget-loading">Checking images…</div>}
|
||||
|
||||
Reference in New Issue
Block a user