Header.tsx 3.4 KB

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