mirror of
https://github.com/thegeneralist01/archivr
synced 2026-07-21 18:55:36 +02:00
Merge branch 'task/auth-topbar'
This commit is contained in:
commit
8edd17d694
1 changed files with 23 additions and 1 deletions
|
|
@ -1,4 +1,18 @@
|
||||||
|
import { useContext, useState } from 'react';
|
||||||
|
import { AuthContext } from '../App.jsx';
|
||||||
|
import { logout as apiLogout } from '../api.js';
|
||||||
|
|
||||||
export default function Topbar({ archives, archiveId, onArchiveChange, view, onViewChange, onCaptureClick }) {
|
export default function Topbar({ archives, archiveId, onArchiveChange, view, onViewChange, onCaptureClick }) {
|
||||||
|
const { currentUser, setCurrentUser } = useContext(AuthContext) ?? {};
|
||||||
|
const [loggingOut, setLoggingOut] = useState(false);
|
||||||
|
|
||||||
|
async function handleLogout() {
|
||||||
|
setLoggingOut(true);
|
||||||
|
await apiLogout();
|
||||||
|
setCurrentUser(null);
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="topbar">
|
<header className="topbar">
|
||||||
<div className="brand">Archivr</div>
|
<div className="brand">Archivr</div>
|
||||||
|
|
@ -15,6 +29,14 @@ export default function Topbar({ archives, archiveId, onArchiveChange, view, onV
|
||||||
))}
|
))}
|
||||||
</nav>
|
</nav>
|
||||||
<button className="capture-button" onClick={onCaptureClick}>+ Capture</button>
|
<button className="capture-button" onClick={onCaptureClick}>+ Capture</button>
|
||||||
|
{currentUser && (
|
||||||
|
<div className="user-menu">
|
||||||
|
<span className="username">{currentUser.username}</span>
|
||||||
|
<button onClick={handleLogout} disabled={loggingOut} className="logout-btn">
|
||||||
|
{loggingOut ? 'Logging out\u2026' : 'Log out'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</header>
|
</header>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue