summaryrefslogtreecommitdiffstats
path: root/frontend/components/Nav.js
blob: 97930875fc8a86e2851132d5cff41e8d929bf4d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import Link from 'next/link';
import styled from 'styled-components';
import { userEnhancer } from '../enhancers/enhancers';
import { compose } from 'react-apollo';
import ToggleCart from './ToggleCart';

const StyledUl = styled.ul`
  margin: 0;
  padding: 0;
  display: flex;
  justify-self: end;
  a,
  button {
    padding: 0 30px;
    display: flex;
    align-items: center;
    position: relative;
    text-transform: uppercase;
    font-weight: 900;
    font-size: 2rem;
    background: none;
    border: 0;
    &:before {
      content: '';
      width: 1px;
      background: ${props => props.theme.lightgrey};
      height: 100%;
      left: 0;
      position: absolute;
      transform: rotate(20deg);
      top: 0;
      bottom: 0;
    }
    &:after {
      height: 2px;
      background: red;
      content: '';
      width: 0;
      position: absolute;
      transform: translateX(-50%);
      transition: width 0.6s;
      transition-timing-function: cubic-bezier(1, -0.65, 0, 2.31);
      left: 50%;
      margin-top: 2rem;
    }
    &:hover,
    &:focus {
      outline: none;
      &:after {
        width: calc(100% - 60px);
      }
    }
  }
  .cart-count {
    background: ${props => props.theme.red};
    color: white;
    border-radius: 50%;
    padding: 5px;
    margin-left: 1rem;
    font-weight: 100;
    font-feature-settings: 'tnum';
    font-variant-numeric: tabular-nums;
  }
`;

const Nav = ({ currentUser }) => (
  <StyledUl>
    <Link prefetch href="/items">
      <a>Shop</a>
    </Link>
    <Link prefetch href="/add">
      <a>Sell</a>
    </Link>
    <Link prefetch href="/signup">
      <a>Sign Up</a>
    </Link>
    <Link prefetch href="/orders">
      <a>Orders</a>
    </Link>
    {currentUser.me ? (
      <ToggleCart
        render={toggle => (
          <button onClick={toggle}>
            My Cart
            <span className="cart-count">
              {currentUser.me.cart.reduce((tally, cartItem) => tally + cartItem.quantity, 0)}
            </span>
          </button>
        )}
      />
    ) : null}
  </StyledUl>
);

export default compose(userEnhancer)(Nav);