diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-06-14 16:44:21 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-06-14 16:44:21 -0400 |
| commit | b1600adec47a04f60e1da07d94a3ed3906ff5aee (patch) | |
| tree | 828f786da6806d7237ee5cbc5df61e552353b85b /finished-application/frontend/components/Nav.js | |
| parent | a95e08cd2dd5d7ec0a0412adae02515a5f9cec4f (diff) | |
starter files
Diffstat (limited to 'finished-application/frontend/components/Nav.js')
| -rw-r--r-- | finished-application/frontend/components/Nav.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/finished-application/frontend/components/Nav.js b/finished-application/frontend/components/Nav.js new file mode 100644 index 0000000..b483376 --- /dev/null +++ b/finished-application/frontend/components/Nav.js @@ -0,0 +1,59 @@ +import React, { Fragment } from 'react'; +import Link from 'next/link'; +import { Query, Mutation } from 'react-apollo'; +import { TOGGLE_CART_MUTATION } from './Cart'; +import User from './User'; +import CartCount from './CartCount'; +import Signout from './Signout'; +import NavStyles from './styles/NavStyles'; + +class Nav extends React.Component { + render() { + // below we set the fetchPolicy to network only so it forces re-fetch on the server + return ( + <User> + {({ data: { me }, error }) => ( + <NavStyles data-test="nav"> + <Link href="/items"> + <a>Shop</a> + </Link> + <Link href="/sell"> + <a>Sell</a> + </Link> + + {!me && ( + <Link 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 /> + <Mutation mutation={TOGGLE_CART_MUTATION}> + {toggleCart => ( + <button onClick={toggleCart}> + My Cart + <CartCount + className="cart-count" + count={me.cart.reduce((tally, cartItem) => tally + cartItem.quantity, 0)} + /> + </button> + )} + </Mutation> + </Fragment> + )} + </NavStyles> + )} + </User> + ); + } +} + +export default Nav; |
