Header.tsx 4.0 KB

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