|
@@ -1,11 +1,13 @@
|
|
|
import React from "react";
|
|
|
import { Link, withRouter } from "react-router-dom";
|
|
|
+import { connect } from "react-redux";
|
|
|
|
|
|
const liArr = [
|
|
|
- { path: "/", id: 1, text: "Main" },
|
|
|
- { path: "/count", id: 2, text: "Counter from redux" },
|
|
|
- { path: "/redux-todo", id: 3, text: "Todo redux" },
|
|
|
- { path: "/remote-todo", id: 4, text: "Remote todo" }
|
|
|
+ { path: "/", id: 1, text: "Main", hideWhenAuth: false },
|
|
|
+ { path: "/count", id: 2, text: "Counter from redux", hideWhenAuth: false },
|
|
|
+ { path: "/redux-todo", id: 3, text: "Todo redux", hideWhenAuth: false },
|
|
|
+ { path: "/remote-todo", id: 4, text: "Remote todo", hideWhenAuth: false },
|
|
|
+ { path: "/auth", id: 5, text: "Auth", hideWhenAuth: true }
|
|
|
];
|
|
|
|
|
|
const header = props => {
|
|
@@ -22,11 +24,13 @@ const header = props => {
|
|
|
<div className="header__logo-box">logo</div>
|
|
|
<nav className="header__nav">
|
|
|
<ul className="header__list">
|
|
|
- {liArr.map(el => (
|
|
|
- <li className="header__item" key={el.id}>
|
|
|
- <Link to={el.path}>{el.text}</Link>
|
|
|
- </li>
|
|
|
- ))}
|
|
|
+ {liArr.map(el =>
|
|
|
+ el.hideWhenAuth && props.user ? null : (
|
|
|
+ <li className="header__item" key={el.id}>
|
|
|
+ <Link to={el.path}>{el.text}</Link>
|
|
|
+ </li>
|
|
|
+ )
|
|
|
+ )}
|
|
|
</ul>
|
|
|
</nav>
|
|
|
<button onClick={event}>Click and wait 5s</button>
|
|
@@ -35,4 +39,8 @@ const header = props => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
-export default withRouter(header);
|
|
|
+const mapStateToProps = state => ({
|
|
|
+ user: state.auth.user
|
|
|
+});
|
|
|
+
|
|
|
+export default connect(mapStateToProps)(withRouter(header));
|