Change "Account" to user email when signed out.

This commit is contained in:
Ray 2023-10-10 09:32:54 +00:00 committed by GitHub
parent f95abb2035
commit 7129071a55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 20 deletions

View File

@ -98,7 +98,7 @@ const signIn = (email, password) => {
}
return (
<div className="App">
<Header items={nav} />
<Header items={nav} user={auth} />
<AuthContext.Provider value={auth}>
<Routes>
<Route path="/" element={<Home greeting="Hey you're at home!" />} />

View File

@ -3,24 +3,38 @@ import Navbar from "react-bootstrap/Navbar"
import Nav from "react-bootstrap/Nav"
import NavDropdown from "react-bootstrap/NavDropdown"
export function Header ( props ) {
// props.items is the value of nav state in App.js
// create a collection of navigation items
const Links = props.items.map( (item, itemkey) => {
return (
<Nav.Link href={item.link} key={itemkey}> {item.label} </Nav.Link>
)
} )
export function Header(props) {
// props.items is the value of nav state in App.js
// create a collection of navigation items
const Links = props.items.map((item, itemkey) => {
return (
<Navbar>
<Container>
<Navbar.Brand>App</Navbar.Brand>
<Nav>
{Links}
<NavDropdown title="Account">
<NavDropdown.Item>Log out</NavDropdown.Item>
</NavDropdown>
</Nav>
</Container>
</Navbar>)
<Nav.Link href={item.link} key={itemkey}> {item.label} </Nav.Link>
)
})
// component for Account
const Account = (props) => {
if (props.user) {
return (
<NavDropdown title="Account">
<NavDropdown.Item href="/signout">Log out</NavDropdown.Item>
</NavDropdown>
)
}
else {
return null
}
}
return (
<Navbar>
<Container>
<Navbar.Brand>App</Navbar.Brand>
<Nav>
{Links}
<NavDropdown title={props.user.email}>
<NavDropdown.Item href="/signout">Log out</NavDropdown.Item>
</NavDropdown>
</Nav>
</Container>
</Navbar>)
}