Fix cache title hydration
This commit is contained in:
@@ -25,6 +25,8 @@ export default function UsersPage() {
|
||||
const [users, setUsers] = useState<AdminUser[]>([])
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [jellyfinSyncStatus, setJellyfinSyncStatus] = useState<string | null>(null)
|
||||
const [jellyfinSyncBusy, setJellyfinSyncBusy] = useState(false)
|
||||
|
||||
const loadUsers = async () => {
|
||||
try {
|
||||
@@ -103,6 +105,28 @@ export default function UsersPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const syncJellyfinUsers = async () => {
|
||||
setJellyfinSyncStatus(null)
|
||||
setJellyfinSyncBusy(true)
|
||||
try {
|
||||
const baseUrl = getApiBase()
|
||||
const response = await authFetch(`${baseUrl}/admin/jellyfin/users/sync`, {
|
||||
method: 'POST',
|
||||
})
|
||||
if (!response.ok) {
|
||||
const text = await response.text()
|
||||
throw new Error(text || 'Sync failed')
|
||||
}
|
||||
const data = await response.json()
|
||||
setJellyfinSyncStatus(`Synced ${data?.imported ?? 0} Jellyfin users.`)
|
||||
await loadUsers()
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
setJellyfinSyncStatus('Could not sync Jellyfin users.')
|
||||
} finally {
|
||||
setJellyfinSyncBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!getToken()) {
|
||||
@@ -121,13 +145,19 @@ export default function UsersPage() {
|
||||
title="Users"
|
||||
subtitle="Manage who can use Magent."
|
||||
actions={
|
||||
<button type="button" onClick={loadUsers}>
|
||||
Reload list
|
||||
</button>
|
||||
<>
|
||||
<button type="button" onClick={loadUsers}>
|
||||
Reload list
|
||||
</button>
|
||||
<button type="button" onClick={syncJellyfinUsers} disabled={jellyfinSyncBusy}>
|
||||
{jellyfinSyncBusy ? 'Syncing Jellyfin users...' : 'Sync Jellyfin users'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<section className="admin-section">
|
||||
{error && <div className="error-banner">{error}</div>}
|
||||
{jellyfinSyncStatus && <div className="status-banner">{jellyfinSyncStatus}</div>}
|
||||
{users.length === 0 ? (
|
||||
<div className="status-banner">No users found yet.</div>
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user