mirror of
https://github.com/thegeneralist01/archivr
synced 2026-07-21 18:55:36 +02:00
feat(auth): user menu and logout button in Topbar
This commit is contained in:
parent
7584e309de
commit
7fcc207de7
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 }) {
|
||||
const { currentUser, setCurrentUser } = useContext(AuthContext) ?? {};
|
||||
const [loggingOut, setLoggingOut] = useState(false);
|
||||
|
||||
async function handleLogout() {
|
||||
setLoggingOut(true);
|
||||
await apiLogout();
|
||||
setCurrentUser(null);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
return (
|
||||
<header className="topbar">
|
||||
<div className="brand">Archivr</div>
|
||||
|
|
@ -15,6 +29,14 @@ export default function Topbar({ archives, archiveId, onArchiveChange, view, onV
|
|||
))}
|
||||
</nav>
|
||||
<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>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue