Header.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import { Flex } from "reflexbox/styled-components";
  2. import React, { FC } from "react";
  3. import Router from "next/router";
  4. import useMedia from "use-media";
  5. import Link from "next/link";
  6. import { useStoreState } from "../store";
  7. import styled from "styled-components";
  8. import { RowCenterV } from "./Layout";
  9. import { Button } from "./Button";
  10. import ALink from "./ALink";
  11. const Li = styled(Flex).attrs({ ml: [12, 24, 32] })`
  12. a {
  13. color: inherit;
  14. :hover {
  15. color: #2196f3;
  16. }
  17. }
  18. `;
  19. const LogoImage = styled.div`
  20. & > a {
  21. position: relative;
  22. display: flex;
  23. align-items: center;
  24. margin: 0 8px 0 0;
  25. font-size: 22px;
  26. font-weight: bold;
  27. text-decoration: none;
  28. color: inherit;
  29. transition: border-color 0.2s ease-out;
  30. }
  31. @media only screen and (max-width: 488px) {
  32. a {
  33. font-size: 18px;
  34. }
  35. }
  36. img {
  37. width: 18px;
  38. margin-right: 11px;
  39. }
  40. `;
  41. const Header: FC = () => {
  42. const { isAuthenticated } = useStoreState(s => s.auth);
  43. const isMobile = useMedia({ maxWidth: 640 });
  44. const login = !isAuthenticated && (
  45. <Li>
  46. <Link href="/login">
  47. <ALink href="/login" title="login / signup" forButton>
  48. <Button height={[32, 40]}>Login / Sign up</Button>
  49. </ALink>
  50. </Link>
  51. </Li>
  52. );
  53. const logout = isAuthenticated && (
  54. <Li>
  55. <Link href="/logout">
  56. <ALink href="/logout" title="logout" fontSize={[14, 16]}>
  57. Log out
  58. </ALink>
  59. </Link>
  60. </Li>
  61. );
  62. const settings = isAuthenticated && (
  63. <Li>
  64. <Link href="/settings">
  65. <ALink href="/settings" title="Settings" forButton>
  66. <Button height={[32, 40]}>Settings</Button>
  67. </ALink>
  68. </Link>
  69. </Li>
  70. );
  71. return (
  72. <Flex
  73. width={1232}
  74. maxWidth="100%"
  75. p={[16, "0 32px"]}
  76. mb={[32, 0]}
  77. height={["auto", "auto", 102]}
  78. justifyContent="space-between"
  79. alignItems={["flex-start", "center"]}
  80. >
  81. <Flex
  82. flexDirection={["column", "row"]}
  83. alignItems={["flex-start", "stretch"]}
  84. >
  85. <LogoImage>
  86. <a
  87. href="/"
  88. title="Homepage"
  89. onClick={e => {
  90. e.preventDefault();
  91. if (window.location.pathname !== "/") Router.push("/");
  92. }}
  93. >
  94. <img src="/images/logo.svg" alt="" />
  95. Kutt.it
  96. </a>
  97. </LogoImage>
  98. {!isMobile && (
  99. <Flex
  100. style={{ listStyle: "none" }}
  101. display={["none", "flex"]}
  102. alignItems="flex-end"
  103. as="ul"
  104. mb="3px"
  105. m={0}
  106. p={0}
  107. >
  108. <Li>
  109. <ALink
  110. href="//github.com/thedevs-network/kutt"
  111. target="_blank"
  112. rel="noopener noreferrer"
  113. title="GitHub"
  114. fontSize={[14, 16]}
  115. >
  116. GitHub
  117. </ALink>
  118. </Li>
  119. <Li>
  120. <Link href="/report">
  121. <ALink href="/report" title="Report abuse" fontSize={[14, 16]}>
  122. Report
  123. </ALink>
  124. </Link>
  125. </Li>
  126. </Flex>
  127. )}
  128. </Flex>
  129. <RowCenterV
  130. m={0}
  131. p={0}
  132. justifyContent="flex-end"
  133. as="ul"
  134. style={{ listStyle: "none" }}
  135. >
  136. <Li>
  137. <Flex display={["flex", "none"]}>
  138. <Link href="/report">
  139. <ALink href="/report" title="Report" fontSize={[14, 16]}>
  140. Report
  141. </ALink>
  142. </Link>
  143. </Flex>
  144. </Li>
  145. {logout}
  146. {settings}
  147. {login}
  148. </RowCenterV>
  149. </Flex>
  150. );
  151. };
  152. export default Header;