From fceade857ecccad6884fe03a973215bd9df1a1e7 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Wed, 16 May 2018 13:53:07 -0400 Subject: simplyfyyyy --- frontend/components/Pagination.js | 1 - frontend/components/Reset.js | 5 +- frontend/components/Search.js | 15 ++++-- frontend/components/Signin.js | 83 ++++++++++++++--------------- frontend/components/Signup.js | 108 +++++++++++++++++++------------------- 5 files changed, 104 insertions(+), 108 deletions(-) (limited to 'frontend/components') diff --git a/frontend/components/Pagination.js b/frontend/components/Pagination.js index d56b100..380026d 100644 --- a/frontend/components/Pagination.js +++ b/frontend/components/Pagination.js @@ -37,7 +37,6 @@ const Pagination = props => ( const { aggregate } = data.itemsConnection; const { page } = props; const pages = Math.ceil(aggregate.count / perPage); - // TODO prefetch this return ( { e.preventDefault(); - const res = await resetMutation(); - // sign them in! - localStorage.setItem('token', res.data.resetPassword.token); - // TODO: Manually call refresh on a Query + await resetMutation(); }; render() { diff --git a/frontend/components/Search.js b/frontend/components/Search.js index eb00d93..9f43d36 100644 --- a/frontend/components/Search.js +++ b/frontend/components/Search.js @@ -64,14 +64,18 @@ class AutoComplete extends React.Component { items: [], loading: false, }; - onChange = debounce(async (e, client) => { + onChange = async (e, client) => { if (!e.target.value) { return this.setState({ items: [] }); } this.setState({ loading: true }); + this.search(client, e.target.value); + }; + + search = debounce(async (client, searchTerm) => { const res = await client.query({ query: SEARCH_ITEMS_QUERY, - variables: { searchTerm: e.target.value }, + variables: { searchTerm }, }); this.setState({ items: res.data.items, loading: false }); }, 350); @@ -112,9 +116,10 @@ class AutoComplete extends React.Component { ))} {/* Found Nothing State */} - {!this.state.items.length && ( - Nothing Found for {inputValue}... - )} + {!this.state.items.length && + !this.state.loading && ( + Nothing Found for {inputValue}... + )} )} diff --git a/frontend/components/Signin.js b/frontend/components/Signin.js index 7a4db8c..23a5835 100644 --- a/frontend/components/Signin.js +++ b/frontend/components/Signin.js @@ -9,14 +9,6 @@ class Signin extends Component { email: `wesbos@gmail.com`, password: 'abc123', }; - - loginUser = async (e, signin, client) => { - e.preventDefault(); - const res = await signin(); - // TODO instead of refetching, can we just use the data returned? - client.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' }); - }; - saveToState = e => { const { name, value } = e.target; this.setState({ [name]: value }); @@ -24,44 +16,49 @@ class Signin extends Component { render() { return ( - - {client => ( - - {(signin, { loading, error }) => ( -
this.loginUser(e, signin, client)}> - -
- + + {(signin, { loading, error }) => ( + { + e.preventDefault(); + signin(); + }} + > + +
+ - + - -
- - )} -
+ +
+ )} -
+ ); } } diff --git a/frontend/components/Signup.js b/frontend/components/Signup.js index ef622ed..624bc10 100644 --- a/frontend/components/Signup.js +++ b/frontend/components/Signup.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { Mutation, ApolloConsumer } from 'react-apollo'; +import { Mutation } from 'react-apollo'; import { SIGNUP_MUTATION, CURRENT_USER_QUERY } from '../queries/queries.graphql'; import Form from './styles/Form'; import Error from './ErrorMessage'; @@ -18,64 +18,62 @@ class Signup extends Component { render() { return ( - - {client => ( - - {(signup, { loading, error }) => ( -
{ - e.preventDefault(); - const res = await signup(); - // TODO can we return theuser from signup? - client.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' }); - }} - > -
- -

Sign Up for an Account

- + + {(signup, { loading, error }) => ( + { + e.preventDefault(); + const res = await signup(); + }} + > +
+ +

Sign Up for an Account

+ - + - + - -
- - )} -
+ +
+ )} -
+ ); } } -- cgit v1.3