Header.tsx 3.8 KB

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