diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-04-05 13:54:22 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-04-05 13:54:22 -0400 |
| commit | f4f10d5eb690a33dd1c112358457a2b987297f26 (patch) | |
| tree | d97326763dd016c13a068fb7dee40fc0b9667f83 /frontend | |
| parent | a75b2491758a451283e2a373bb3fbe886520b345 (diff) | |
work
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/components/CartCount.js | 12 | ||||
| -rw-r--r-- | frontend/components/Header.js | 16 | ||||
| -rw-r--r-- | frontend/components/Items.js | 17 | ||||
| -rw-r--r-- | frontend/components/Nav.js | 18 | ||||
| -rw-r--r-- | frontend/components/PleaseSignIn.js | 21 | ||||
| -rw-r--r-- | frontend/components/Search.js | 62 | ||||
| -rw-r--r-- | frontend/components/Signup.js | 9 | ||||
| -rw-r--r-- | frontend/components/UpdateItem.js | 3 | ||||
| -rw-r--r-- | frontend/components/styles/Form.js | 13 | ||||
| -rw-r--r-- | frontend/lib/withData.js | 1 | ||||
| -rw-r--r-- | frontend/package-lock.json | 14 | ||||
| -rw-r--r-- | frontend/package.json | 3 | ||||
| -rw-r--r-- | frontend/pages/add.js | 6 | ||||
| -rw-r--r-- | frontend/pages/admin/update.js | 5 | ||||
| -rw-r--r-- | frontend/pages/signup.js | 4 |
15 files changed, 138 insertions, 66 deletions
diff --git a/frontend/components/CartCount.js b/frontend/components/CartCount.js index 5af472a..1cc4e47 100644 --- a/frontend/components/CartCount.js +++ b/frontend/components/CartCount.js @@ -5,7 +5,9 @@ const Dot = styled.div` background: ${props => props.theme.red}; color: white; border-radius: 50%; - padding: 5px; + padding: 0.5rem; + line-height: 2rem; + min-width: 3rem; margin-left: 1rem; font-weight: 100; font-feature-settings: 'tnum'; @@ -42,13 +44,7 @@ const AnimationStyles = styled.span` const CartCount = ({ count }) => ( <AnimationStyles> <TransitionGroup> - <CSSTransition - unmountOnExit - className="count" - classNames="count" - key={count} - timeout={{ enter: 400, exit: 400 }} - > + <CSSTransition unmountOnExit className="count" classNames="count" key={count} timeout={{ enter: 400, exit: 400 }}> <Dot>{count}</Dot> </CSSTransition> </TransitionGroup> diff --git a/frontend/components/Header.js b/frontend/components/Header.js index 053a18b..4e631a0 100644 --- a/frontend/components/Header.js +++ b/frontend/components/Header.js @@ -20,6 +20,10 @@ const StyledHeader = styled.header` grid-template-columns: auto 1fr; justify-content: space-between; align-items: stretch; + @media (max-width: 1300px) { + grid-template-columns: 1fr; + justify-content: center; + } } .sub-bar { display: grid; @@ -31,14 +35,20 @@ const StyledHeader = styled.header` const Logo = styled.h1` font-size: 4rem; margin-left: 2rem; - transform: skew(-5deg); + position: relative; + z-index: 2; + transform: skew(-7deg); a { - padding: 1rem 1.5rem; + padding: 0.5rem 1rem; background: ${props => props.theme.red}; color: white; letter-spacing: -2px; text-transform: uppercase; } + @media (max-width: 1300px) { + margin: 0; + text-align: center; + } `; const Header = props => ( @@ -46,7 +56,7 @@ const Header = props => ( <div className="bar"> <Logo> <Link href="/"> - <a>Sick Fits!</a> + <a>Sick Fits!</a> </Link> </Logo> <Nav /> diff --git a/frontend/components/Items.js b/frontend/components/Items.js index d0e39e9..e26408e 100644 --- a/frontend/components/Items.js +++ b/frontend/components/Items.js @@ -9,7 +9,7 @@ import { ALL_ITEMS_QUERY } from '../queries/index'; const Items = styled.div` display: grid; - grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); + grid-template-columns: 1fr 1fr; grid-gap: 60px; max-width: ${props => props.theme.maxWidth}; margin: 0 auto; @@ -44,20 +44,7 @@ class ItemList extends React.Component { {({ data, error, loading, variables, refetch }) => { if (loading) return <div>Loading</div>; if (error) return <div>Error</div>; - return ( - <Items key={this.props.page}> - {data.items.map(item => <Item key={item.id} item={item} />)} - <button - onClick={() => { - console.log('Refetching..'); - console.log(refetch); - refetch(); - }} - > - refetch - </button> - </Items> - ); + return <Items key={this.props.page}>{data.items.map(item => <Item key={item.id} item={item} />)}</Items>; }} </Query> <Pagination page={this.props.page} /> diff --git a/frontend/components/Nav.js b/frontend/components/Nav.js index 7e65ec5..34c00cf 100644 --- a/frontend/components/Nav.js +++ b/frontend/components/Nav.js @@ -6,33 +6,33 @@ import { CURRENT_USER_QUERY } from '../queries/index'; import CartCount from './CartCount'; import Signout from './Signout'; import { UIContext } from './UIContext'; -import Dump from './Dump'; const StyledUl = styled.ul` margin: 0; padding: 0; display: flex; justify-self: end; + font-size: 2rem; a, button { - padding: 0 30px; + padding: 1rem 3rem; display: flex; align-items: center; position: relative; text-transform: uppercase; font-weight: 900; - font-size: 2rem; + font-size: 1em; background: none; border: 0; cursor: pointer; &:before { content: ''; - width: 1px; + width: 2px; background: ${props => props.theme.lightgrey}; height: 100%; left: 0; position: absolute; - transform: rotate(20deg); + transform: skew(-20deg); top: 0; bottom: 0; } @@ -43,7 +43,7 @@ const StyledUl = styled.ul` width: 0; position: absolute; transform: translateX(-50%); - transition: width 0.6s; + transition: width 0.4s; transition-timing-function: cubic-bezier(1, -0.65, 0, 2.31); left: 50%; margin-top: 2rem; @@ -56,6 +56,12 @@ const StyledUl = styled.ul` } } } + @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 { diff --git a/frontend/components/PleaseSignIn.js b/frontend/components/PleaseSignIn.js new file mode 100644 index 0000000..bd96842 --- /dev/null +++ b/frontend/components/PleaseSignIn.js @@ -0,0 +1,21 @@ +import { Query } from 'react-apollo'; +import { CURRENT_USER_QUERY } from '../queries/index'; +import Signin from './Signin'; + +const PleaseSignIn = props => ( + <Query query={CURRENT_USER_QUERY}> + {({ data }) => { + if (data.me) { + return props.children; + } + return ( + <div> + <p>Please sign in before continuing!</p> + <Signin /> + </div> + ); + }} + </Query> +); + +export default PleaseSignIn; diff --git a/frontend/components/Search.js b/frontend/components/Search.js index 45f5961..b8816ec 100644 --- a/frontend/components/Search.js +++ b/frontend/components/Search.js @@ -2,6 +2,8 @@ import Downshift from 'downshift'; import { Query } from 'react-apollo'; import Router from 'next/router'; import styled from 'styled-components'; +import debounce from 'lodash.debounce'; + import { SEARCH_ITEMS_QUERY } from '../queries'; function routeToItem(item) { @@ -18,9 +20,6 @@ const DropDown = styled.div` width: 100%; z-index: 2; border: 1px solid ${props => props.theme.lightgrey}; - input { - border: 0; - } `; const DropDownItem = styled.div` @@ -39,15 +38,22 @@ const DropDownItem = styled.div` const SearchStyles = styled.div` position: relative; + input { + width: 100%; + padding: 10px; + border: 0; + font-size: 2rem; + } `; function AutoComplete(props) { - const { items, onChange } = props; + const { items, onChange, loading } = props; return ( <Downshift onChange={routeToItem} itemToString={i => (i === null ? '' : i.title)}> - {({ getInputProps, getItemProps, isOpen, inputValue, selectedItem, highlightedIndex }) => ( + {({ getInputProps, getItemProps, isOpen, inputValue, highlightedIndex }) => ( <div> {/* This is the searchInput */} + {loading && 'LOADING'} <input {...getInputProps({ placeholder: 'Search For Item', @@ -55,18 +61,22 @@ function AutoComplete(props) { onChange: e => { props.refetch({ searchTerm: e.target.value }); }, - style: { fontSize: '20px', padding: '10px', display: 'block', width: '100%' }, })} /> {isOpen ? ( <DropDown> {/* This is the Dropdown */} {items.map((item, index) => ( - <DropDownItem {...getItemProps({ item })} key={item.id} highlighted={highlightedIndex === index}> + <DropDownItem + {...getItemProps({ item })} + key={item.id} + highlighted={highlightedIndex === index} + > <img width="50" src={item.image} alt={item.title} /> {item.title} </DropDownItem> ))} + {!items.length && <DropDownItem>Nothing Found for {inputValue}...</DropDownItem>} </DropDown> ) : null} </div> @@ -76,14 +86,34 @@ function AutoComplete(props) { } // TODO: This should not fire a queryon page load -const Search = () => ( - <SearchStyles> - <Query query={SEARCH_ITEMS_QUERY} variables={{ searchTerm: '' }}> - {({ data, error, refetch }) => ( - <AutoComplete items={data.items || []} onChange={selectedItem => console.log(selectedItem)} refetch={refetch} /> - )} - </Query> - </SearchStyles> -); +class Search extends React.Component { + state = { + skip: true, + }; + componentDidMount() { + this.setState({ skip: false }); + } + render() { + return ( + <SearchStyles> + <Query + skip={this.state.skip} + query={SEARCH_ITEMS_QUERY} + variables={{ searchTerm: '' }} + fetchPolicy="network-only" + > + {({ data, error, loading, refetch }) => + console.log('QUERY', data.items) || ( + <AutoComplete + loading={loading} + items={data.items || []} + refetch={debounce(refetch, 300)} + /> + )} + </Query> + </SearchStyles> + ); + } +} export default Search; diff --git a/frontend/components/Signup.js b/frontend/components/Signup.js index 4adc1ad..2fc8950 100644 --- a/frontend/components/Signup.js +++ b/frontend/components/Signup.js @@ -1,8 +1,9 @@ import React, { Component } from 'react'; import { Mutation } from 'react-apollo'; -import { SIGNUP_MUTATION } from '../queries'; +import { SIGNUP_MUTATION, CURRENT_USER_QUERY } from '../queries'; import Form from './styles/Form'; import Error from './ErrorMessage'; +import { client } from '../lib/withData'; class Signup extends Component { state = { @@ -21,9 +22,11 @@ class Signup extends Component { <Mutation mutation={SIGNUP_MUTATION} variables={this.state}> {(signup, { loading, error }) => ( <Form - onSubmit={e => { + onSubmit={async e => { e.preventDefault(); - signup(); + const res = await signup(); + localStorage.setItem('token', res.data.signup.token); + client.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' }); }} > <fieldset disabled={loading} aria-busy={loading}> diff --git a/frontend/components/UpdateItem.js b/frontend/components/UpdateItem.js index 4292d41..a96c8f7 100644 --- a/frontend/components/UpdateItem.js +++ b/frontend/components/UpdateItem.js @@ -38,7 +38,8 @@ class UpdateItem extends Component { render() { return ( <Query query={SINGLE_ITEM_QUERY} variables={{ id: this.props.id }}> - {({ data: { items } }) => { + {({ data: { items }, loading }) => { + if (loading) return <p>Loading...</p>; if (!items || !items.length) return <p>Item Not Found</p>; const [item] = items; return ( diff --git a/frontend/components/styles/Form.js b/frontend/components/styles/Form.js index 4fd8029..5717130 100644 --- a/frontend/components/styles/Form.js +++ b/frontend/components/styles/Form.js @@ -17,20 +17,19 @@ const Form = styled.form` background: rgba(0, 0, 0, 0.02); border: 5px solid white; padding: 20px; - font-size: 2.5rem; + font-size: 1.5rem; + line-height: 1.5; font-weight: 600; label { - margin-bottom: 1rem; display: block; + margin-bottom: 1rem; } input, textarea, select { - margin-top: 2rem; - margin-bottom: 2rem; width: 100%; - padding: 1rem; - font-size: 2rem; + padding: 0.5rem; + font-size: 1rem; border: 1px solid black; &:focus { outline: 0; @@ -45,7 +44,7 @@ const Form = styled.form` border: 0; font-size: 2rem; font-weight: 600; - padding: 1rem 2rem; + padding: 0.5rem 1.2rem; } fieldset { border: 0; diff --git a/frontend/lib/withData.js b/frontend/lib/withData.js index 5c4614f..ada9675 100644 --- a/frontend/lib/withData.js +++ b/frontend/lib/withData.js @@ -10,7 +10,6 @@ const client = new ApolloClient({ request: operation => { console.log(operation); if (typeof localStorage !== 'undefined' && localStorage.getItem('token')) { - console.log(`Bearer ${localStorage.getItem('token')}`); operation.setContext({ headers: { authorization: `Bearer ${localStorage.getItem('token')}`, diff --git a/frontend/package-lock.json b/frontend/package-lock.json index ce55ad2..46aaf28 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -7808,6 +7808,11 @@ "lodash.keys": "3.1.2" } }, + "lodash.debounce": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", + "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=" + }, "lodash.flattendeep": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", @@ -10056,6 +10061,15 @@ "prop-types": "15.6.1" } }, + "react-debounce-input": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/react-debounce-input/-/react-debounce-input-3.2.0.tgz", + "integrity": "sha1-aXjGBh2Jj1SfQEF/sNLrvs9Qqqo=", + "requires": { + "lodash.debounce": "4.0.8", + "prop-types": "15.6.1" + } + }, "react-deep-force-update": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/react-deep-force-update/-/react-deep-force-update-2.1.1.tgz", diff --git a/frontend/package.json b/frontend/package.json index 15ec605..e182ba9 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -27,6 +27,7 @@ "graphql": "^0.13.2", "graphql-tag": "^2.8.0", "isomorphic-fetch": "^2.2.1", + "lodash.debounce": "^4.0.8", "next": "^5.1.0", "next-apollo": "^1.0.13", "next-with-apollo": "^1.0.6", @@ -111,4 +112,4 @@ } } } -} +}
\ No newline at end of file diff --git a/frontend/pages/add.js b/frontend/pages/add.js index 9b8c333..eb0dd1d 100644 --- a/frontend/pages/add.js +++ b/frontend/pages/add.js @@ -2,13 +2,15 @@ import { Component } from 'react'; import Page from '../components/Page'; import withData from '../lib/withData'; import CreateItem from '../components/CreateItem'; +import PleaseSignIn from '../components/PleaseSignIn'; const Home = props => { const page = parseInt(props.url.query.page) || 1; return ( <Page> - <h2>Add an Item</h2> - <CreateItem /> + <PleaseSignIn> + <CreateItem /> + </PleaseSignIn> </Page> ); }; diff --git a/frontend/pages/admin/update.js b/frontend/pages/admin/update.js index 2731f05..2f445d7 100644 --- a/frontend/pages/admin/update.js +++ b/frontend/pages/admin/update.js @@ -2,12 +2,15 @@ import { Component } from 'react'; import withData from '../../lib/withData'; import UpdateItem from '../../components/UpdateItem'; import Page from '../../components/Page'; +import PleaseSignIn from '../../components/PleaseSignIn'; class Home extends Component { render() { return ( <Page> - <UpdateItem id={this.props.url.query.id} /> + <PleaseSignIn> + <UpdateItem id={this.props.url.query.id} /> + </PleaseSignIn> </Page> ); } diff --git a/frontend/pages/signup.js b/frontend/pages/signup.js index d0b4135..d9bc5e9 100644 --- a/frontend/pages/signup.js +++ b/frontend/pages/signup.js @@ -8,8 +8,8 @@ import ResetRequest from '../components/ResetRequest'; const Columns = styled.div` display: grid; - grid-template-columns: repeat(3, 1fr); - grid-gap: 50px; + grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); + grid-gap: 20px; `; const SignUpPage = () => ( |
