MobileSidebar.jsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import '../css/MobileSidebar.css'
  2. import Home from "../icons/Home.jsx"
  3. import Person from "../icons/Person.jsx"
  4. import Search from "../icons/SearchIcon.jsx"
  5. import Cookies from "js-cookie"
  6. import { config, signedIn } from "../main.jsx"
  7. import Wrong2 from '../icons/Wrong2.jsx'
  8. import { useNavigate } from 'react-router'
  9. function HajeeberButton(props) {
  10. const {size, navigate} = props;
  11. if (signedIn()) {
  12. return <>
  13. <button onClick={() => {
  14. if (signedIn()) {
  15. navigate("/profile");
  16. } else {
  17. navigate("/login");
  18. }
  19. }}>
  20. <img src={`${config.serverURL + "/account/myself/picture"}`} width={size} height={size}></img>
  21. hajeeber
  22. </button>
  23. </>
  24. } else {
  25. return <>
  26. <button onClick={() => {
  27. if (signedIn()) {
  28. navigate("/profile");
  29. } else {
  30. navigate("/login");
  31. }
  32. }}>
  33. <Person size={size} />
  34. hajeeber
  35. </button>
  36. </>
  37. }
  38. }
  39. function LogOutButton(props) {
  40. const size = props.size;
  41. if(signedIn()) {
  42. return <>
  43. <li>
  44. <button onClick={logOut}>
  45. <Wrong2 size={size} />
  46. log out
  47. </button>
  48. </li>
  49. </>
  50. } else {
  51. return
  52. }
  53. }
  54. function logOut() {
  55. Cookies.remove("token");
  56. window.location.reload();
  57. }
  58. function MobileSidebar() {
  59. let size = 40;
  60. let navigate = useNavigate();
  61. return (
  62. <>
  63. <div className="sidebar-container">
  64. <ul className="mobile-sidebar">
  65. <li>
  66. <button onClick={() => {
  67. navigate("/");
  68. }}>
  69. <Home size={size} />
  70. home
  71. </button>
  72. </li>
  73. <li>
  74. <button>
  75. <Search size={size} />
  76. search
  77. </button>
  78. </li>
  79. <li>
  80. <button>
  81. <Person size={size} />
  82. friends
  83. </button>
  84. </li>
  85. <li>
  86. <HajeeberButton size={size} navigate={navigate} />
  87. </li>
  88. <LogOutButton size={size} />
  89. </ul>
  90. </div>
  91. </>
  92. )
  93. }
  94. export default MobileSidebar