feat(manage): add manual resync button for games
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
ExternalLinkIcon,
|
ExternalLinkIcon,
|
||||||
TrashIcon,
|
TrashIcon,
|
||||||
Gamepad2Icon,
|
Gamepad2Icon,
|
||||||
|
RefreshCwIcon,
|
||||||
} from "lucide-react"
|
} from "lucide-react"
|
||||||
|
|
||||||
interface Game {
|
interface Game {
|
||||||
@@ -45,6 +46,7 @@ export function GamesClient() {
|
|||||||
const [search, setSearch] = useState("")
|
const [search, setSearch] = useState("")
|
||||||
const [offset, setOffset] = useState(0)
|
const [offset, setOffset] = useState(0)
|
||||||
const [deletingIds, setDeletingIds] = useState<Set<string>>(new Set())
|
const [deletingIds, setDeletingIds] = useState<Set<string>>(new Set())
|
||||||
|
const [resyncingIds, setResyncingIds] = useState<Set<string>>(new Set())
|
||||||
|
|
||||||
const isSearchChangeRef = useRef(false)
|
const isSearchChangeRef = useRef(false)
|
||||||
|
|
||||||
@@ -93,6 +95,32 @@ export function GamesClient() {
|
|||||||
}
|
}
|
||||||
}, [search, offset])
|
}, [search, offset])
|
||||||
|
|
||||||
|
const handleResync = async (game: Game) => {
|
||||||
|
setResyncingIds((prev) => new Set(prev).add(game.id))
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/games/${game.id}/sync`, {
|
||||||
|
method: "POST",
|
||||||
|
})
|
||||||
|
if (res.ok) {
|
||||||
|
setGames((prev) =>
|
||||||
|
prev.map((g) =>
|
||||||
|
g.id === game.id
|
||||||
|
? { ...g, syncStatus: "synced", lastSync: new Date().toISOString() }
|
||||||
|
: g
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Resync failed:", error)
|
||||||
|
} finally {
|
||||||
|
setResyncingIds((prev) => {
|
||||||
|
const next = new Set(prev)
|
||||||
|
next.delete(game.id)
|
||||||
|
return next
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleDelete = async (game: Game) => {
|
const handleDelete = async (game: Game) => {
|
||||||
if (!confirm(`Are you sure you want to delete "${game.title}"?`)) return
|
if (!confirm(`Are you sure you want to delete "${game.title}"?`)) return
|
||||||
setDeletingIds((prev) => new Set(prev).add(game.id))
|
setDeletingIds((prev) => new Set(prev).add(game.id))
|
||||||
@@ -237,6 +265,18 @@ export function GamesClient() {
|
|||||||
<ExternalLinkIcon className="h-3.5 w-3.5" />
|
<ExternalLinkIcon className="h-3.5 w-3.5" />
|
||||||
View
|
View
|
||||||
</Link>
|
</Link>
|
||||||
|
<button
|
||||||
|
onClick={() => handleResync(game)}
|
||||||
|
disabled={resyncingIds.has(game.id)}
|
||||||
|
className="flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs font-medium bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 transition-colors cursor-pointer disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{resyncingIds.has(game.id) ? (
|
||||||
|
<Loader2 className="h-3.5 w-3.5 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<RefreshCwIcon className="h-3.5 w-3.5" />
|
||||||
|
)}
|
||||||
|
Resync
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => handleDelete(game)}
|
onClick={() => handleDelete(game)}
|
||||||
disabled={deletingIds.has(game.id)}
|
disabled={deletingIds.has(game.id)}
|
||||||
|
|||||||
Reference in New Issue
Block a user