Header.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React, { useState, useEffect } from "react";
  2. import { Link } from "react-router-dom";
  3. import { connect } from "react-redux";
  4. import { logOut } from "../actions/authActions";
  5. import { useHistory } from "react-router-dom";
  6. const Header = ({ logOut }) => {
  7. let history = useHistory();
  8. function onLogOut() {
  9. logOut();
  10. history.push("/");
  11. }
  12. return (
  13. <div className="header">
  14. <ul className="mainMenu">
  15. <li>
  16. <h2>gRomkoPlayer</h2>
  17. </li>
  18. <li onClick={() => history.push("/private")}>
  19. <h2>Library</h2>
  20. </li>
  21. <li onClick={() => history.push("/all_playlists")}>
  22. <h2>All Playlists</h2>
  23. </li>
  24. <li onClick={() => history.push("/my_playlists")}>
  25. <h2>My Playlists</h2>
  26. </li>
  27. <li onClick={() => history.push("/search")}>
  28. <h2>Search</h2>
  29. </li>
  30. <li className="userMenu">
  31. <h2>User: {localStorage.user}</h2>
  32. <ul className="userMenu-child">
  33. <li onClick={() => onLogOut()}>Log out</li>
  34. </ul>
  35. </li>
  36. </ul>
  37. </div>
  38. );
  39. };
  40. const mapStateToProps = (state) => ({
  41. state: state,
  42. });
  43. export default connect(mapStateToProps, { logOut })(Header);