Header.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import { Flex } from "rebass/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 Image from "next/image";
  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. padding: 0;
  34. }
  35. @media only screen and (max-width: 488px) {
  36. a {
  37. font-size: 18px;
  38. }
  39. }
  40. span {
  41. margin-right: 10px !important;
  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. <ALink
  50. href="/login"
  51. title={!DISALLOW_REGISTRATION ? "login / signup" : "login"}
  52. forButton
  53. isNextLink
  54. >
  55. <Button height={[32, 40]}>
  56. {!DISALLOW_REGISTRATION ? "Log in / Sign up" : "Log in"}
  57. </Button>
  58. </ALink>
  59. </Li>
  60. );
  61. const logout = isAuthenticated && (
  62. <Li>
  63. <ALink href="/logout" title="logout" fontSize={[14, 16]} isNextLink>
  64. Log out
  65. </ALink>
  66. </Li>
  67. );
  68. const settings = isAuthenticated && (
  69. <Li>
  70. <ALink href="/settings" title="Settings" forButton isNextLink>
  71. <Button height={[32, 40]}>Settings</Button>
  72. </ALink>
  73. </Li>
  74. );
  75. return (
  76. <Flex
  77. width={1232}
  78. maxWidth="100%"
  79. p={[16, "0 32px"]}
  80. mb={[32, 0]}
  81. height={["auto", "auto", 102]}
  82. justifyContent="space-between"
  83. alignItems={["flex-start", "center"]}
  84. >
  85. <Flex
  86. flexDirection={["column", "row"]}
  87. alignItems={["flex-start", "stretch"]}
  88. >
  89. <LogoImage>
  90. <ALink
  91. href="/"
  92. title="Homepage"
  93. onClick={(e) => {
  94. e.preventDefault();
  95. if (window.location.pathname !== "/") Router.push("/");
  96. }}
  97. forButton
  98. isNextLink
  99. >
  100. <Image
  101. src="/images/logo.svg"
  102. alt="kutt logo"
  103. width={18}
  104. height={24}
  105. />
  106. {publicRuntimeConfig.SITE_NAME}
  107. </ALink>
  108. </LogoImage>
  109. {!isMobile && (
  110. <Flex
  111. style={{ listStyle: "none" }}
  112. display={["none", "flex"]}
  113. alignItems="flex-end"
  114. as="ul"
  115. m={0}
  116. px={0}
  117. pt={0}
  118. pb="2px"
  119. >
  120. <Li>
  121. <ALink
  122. href="//github.com/thedevs-network/kutt"
  123. target="_blank"
  124. rel="noopener noreferrer"
  125. title="GitHub"
  126. fontSize={[14, 16]}
  127. >
  128. GitHub
  129. </ALink>
  130. </Li>
  131. <Li>
  132. <ALink
  133. href="/report"
  134. title="Report abuse"
  135. fontSize={[14, 16]}
  136. isNextLink
  137. >
  138. Report
  139. </ALink>
  140. </Li>
  141. </Flex>
  142. )}
  143. </Flex>
  144. <RowCenterV
  145. m={0}
  146. p={0}
  147. justifyContent="flex-end"
  148. as="ul"
  149. style={{ listStyle: "none" }}
  150. >
  151. {isMobile && (
  152. <Li>
  153. <Flex>
  154. <ALink
  155. href="/report"
  156. title="Report"
  157. fontSize={[14, 16]}
  158. isNextLink
  159. >
  160. Report
  161. </ALink>
  162. </Flex>
  163. </Li>
  164. )}
  165. {logout}
  166. {settings}
  167. {login}
  168. </RowCenterV>
  169. </Flex>
  170. );
  171. };
  172. export default Header;