add individual library scanning

This commit is contained in:
Garret Patti
2026-04-12 13:51:51 -04:00
parent 7e9ba6e014
commit aae41e9803
5 changed files with 105 additions and 1 deletions

View File

@@ -0,0 +1,53 @@
'use client'
import { useState } from 'react'
interface Props {
libraryId: string
}
export default function ScanLibraryButton({ libraryId }: Props) {
const [scanning, setScanning] = useState(false)
const [message, setMessage] = useState<string | null>(null)
const handleScan = async () => {
setScanning(true)
setMessage(null)
try {
const res = await fetch(`/api/scan/${encodeURIComponent(libraryId)}`, { method: 'POST' })
if (res.status === 409) {
setMessage('A scan is already in progress.')
}
} catch {
setMessage('Failed to start scan.')
} finally {
setScanning(false)
}
}
return (
<div className="flex items-center gap-3">
<button
onClick={handleScan}
disabled={scanning}
className="text-sm px-3 py-1.5 rounded-lg transition-colors disabled:opacity-50"
style={{ backgroundColor: 'var(--border)', color: 'var(--text-secondary)' }}
onMouseEnter={(e) => {
if (!scanning) (e.currentTarget as HTMLElement).style.color = 'var(--text-primary)'
}}
onMouseLeave={(e) => {
;(e.currentTarget as HTMLElement).style.color = 'var(--text-secondary)'
}}
>
{scanning ? 'Scanning…' : 'Scan'}
</button>
{message && (
<span className="text-xs" style={{ color: 'var(--text-secondary)' }}>
{message}
</span>
)}
</div>
)
}