mirror of
https://github.com/thegeneralist01/archivr
synced 2026-12-04 18:56:44 +01:00
fix(frontend): admin Archives tab shows paths; drop path from non-admin view
The server now returns archive_path only to admins. The non-admin screen no longer renders an empty line, and the admin tab re-fetches the archive list so paths show even when the cached list was fetched before login. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4b328c4fc8
commit
17c8fc78e6
1 changed files with 11 additions and 4 deletions
|
|
@ -2,7 +2,7 @@ import { useState, useEffect, useContext, useCallback } from 'react'
|
|||
import { AuthContext } from '../App.jsx'
|
||||
import {
|
||||
listAdminUsers, createAdminUser, setUserStatus, assignRole, removeRole,
|
||||
listRoles, createRole
|
||||
listRoles, createRole, fetchArchives
|
||||
} from '../api.js'
|
||||
|
||||
const ROLE_ADMIN = 4
|
||||
|
|
@ -14,6 +14,9 @@ export default function AdminView({ archives }) {
|
|||
const [tab, setTab] = useState('users')
|
||||
const [users, setUsers] = useState([])
|
||||
const [roles, setRoles] = useState([])
|
||||
// The server only includes archive_path for admins, and the archives prop may have been
|
||||
// fetched anonymously (before login), so admins re-fetch the list for the Archives tab.
|
||||
const [adminArchives, setAdminArchives] = useState(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
|
|
@ -47,6 +50,11 @@ export default function AdminView({ archives }) {
|
|||
|
||||
useEffect(() => { refresh() }, [refresh])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAdmin) return
|
||||
fetchArchives().then(setAdminArchives).catch(() => {})
|
||||
}, [isAdmin])
|
||||
|
||||
async function handleToggleStatus(user) {
|
||||
const next = user.status === 'active' ? 'disabled' : 'active'
|
||||
try {
|
||||
|
|
@ -102,7 +110,6 @@ export default function AdminView({ archives }) {
|
|||
{archives.map(a => (
|
||||
<div key={a.id} className="admin-archive">
|
||||
<strong>{a.label}</strong>
|
||||
<div className="muted">{a.archive_path}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
|
@ -204,10 +211,10 @@ export default function AdminView({ archives }) {
|
|||
<div className="admin-section">
|
||||
<h2>Mounted Archives</h2>
|
||||
<div className="admin-list">
|
||||
{archives.map(a => (
|
||||
{(adminArchives ?? archives).map(a => (
|
||||
<div key={a.id} className="admin-archive">
|
||||
<strong>{a.label}</strong>
|
||||
<div className="muted">{a.archive_path}</div>
|
||||
{a.archive_path && <div className="muted">{a.archive_path}</div>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue