blob: acfdfd16e3b308cd478bf65caa343f7cbbbd442f (
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
import React, { Fragment } from 'react';
import Link from 'next/link';
import styled from 'styled-components';
import { Query } from 'react-apollo';
import { CURRENT_USER_QUERY, LOCAL_STATE_QUERY } from '../queries/queries';
import CartCount from './CartCount';
import Signout from './Signout';
import { ApolloConsumer } from 'react-apollo';
const StyledUl = styled.ul`
margin: 0;
padding: 0;
display: flex;
justify-self: end;
font-size: 2rem;
a,
button {
padding: 1rem 3rem;
display: flex;
align-items: center;
position: relative;
text-transform: uppercase;
font-weight: 900;
font-size: 1em;
background: none;
border: 0;
cursor: pointer;
@media (max-width: 700px) {
font-size: 10px;
padding: 0 10px;
}
&:before {
content: '';
width: 2px;
background: ${props => props.theme.lightgrey};
height: 100%;
left: 0;
position: absolute;
transform: skew(-20deg);
top: 0;
bottom: 0;
}
&:after {
height: 2px;
background: red;
content: '';
width: 0;
position: absolute;
transform: translateX(-50%);
transition: width 0.4s;
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);
}
}
}
@media (max-width: 1300px) {
border-top: 1px solid ${props => props.theme.lightgrey};
width: 100%;
justify-content: center;
font-size: 1.5rem;
}
`;
class Nav extends React.Component {
componentDidMount() {
console.log('NAV MOUNTED');
}
render() {
return (
<Query query={CURRENT_USER_QUERY} ssr={false}>
{({ data: { me }, refetch }) => (
<StyledUl>
<Link prefetch href="/items">
<a>Shop</a>
</Link>
<Link prefetch href="/add">
<a>Sell</a>
</Link>
{!me && (
<Link prefetch href="/signup">
<a>Sign In</a>
</Link>
)}
{me && (
<Fragment>
<Link href="/orders">
<a>Orders</a>
</Link>
<Link href="/me">
<a>My Account</a>
</Link>
<Signout />
<ApolloConsumer>
{cache => (
<button onClick={() => cache.writeData({ data: { cartOpen: true } })}>
My Cart
<CartCount
className="cart-count"
count={me.cart.reduce((tally, cartItem) => tally + cartItem.quantity, 0)}
/>
</button>
)}
</ApolloConsumer>
</Fragment>
)}
</StyledUl>
)}
</Query>
);
}
}
export default Nav;
|