From ecc58452e82435be3e64f748563d156360bd2f67 Mon Sep 17 00:00:00 2001 From: Tara Whirley Date: Wed, 4 Apr 2018 17:13:51 -0400 Subject: [PATCH] fix(AllUsers): filtering --- src/components/AdvancedSearch.js | 64 ++++++++++++++++--- src/components/AllUsers.js | 52 +++++++++------- src/components/CommentCard.js | 2 +- src/components/EditProfile.js | 104 ++++++++++++++++++++++++------- src/components/PostCard.js | 2 +- src/components/SearchCard.js | 2 +- src/components/UserProfile.js | 4 +- 7 files changed, 174 insertions(+), 56 deletions(-) diff --git a/src/components/AdvancedSearch.js b/src/components/AdvancedSearch.js index 295cbac..577b2d2 100644 --- a/src/components/AdvancedSearch.js +++ b/src/components/AdvancedSearch.js @@ -4,8 +4,8 @@ import { Button, Form, Select } from 'semantic-ui-react' const AdvancedSearch = (props) => { const options = [ - { key: 'GH', text: 'GH', value: 'GH' }, - { key: 'FS', text: 'FS', value: 'FS' }, + { key: 'GH', text: 'GH', value: 'gh' }, + { key: 'FS', text: 'FS', value: 'fs' }, ] return (
@@ -28,12 +28,62 @@ const AdvancedSearch = (props) => { name="cohortId" />
- + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { - filteredUsers.push(user.data()); - }) - currentComponent.setState({ - allUsers: filteredUsers + .get() + .then(function (users) { + let filteredUsers = []; + users.forEach(user => { + filteredUsers.push(user.data()); + }) + currentComponent.setState({ + allUsers: filteredUsers + }) }) - }) } } @@ -94,7 +94,7 @@ class AllUsers extends Component { if ( this.state.cohort || this.state.cohortId || - this.state.city || + this.state.state || this.state.company || this.state.industry ) { @@ -106,8 +106,8 @@ class AllUsers extends Component { if (this.state.cohortId) { queryParams.push(`cohortId=${this.state.cohortId}`); } - if (this.state.city) { - queryParams.push(`city=${this.state.city}`); + if (this.state.state) { + queryParams.push(`state=${this.state.state}`); } if (this.state.company) { queryParams.push(`company=${this.state.company}`); @@ -116,12 +116,23 @@ class AllUsers extends Component { searchResultsUrl += queryParamsString; history.push(searchResultsUrl); } + this.setState({ + cohort: '', + cohortId: '', + state: '', + company: '', + industry: '' + }) } onInputChange = (evt, param) => { evt.preventDefault() + if(param){ this.setState({ [param.name]: param.value.toLowerCase() }) + } else { + this.setState({[evt.target.name]: evt.target.value}) + } } @@ -151,12 +162,11 @@ class AllUsers extends Component { render() { - console.log('STATE IN ALL USERS: ',this.state) let filteredUsers; if (this.state.searchVal) { filteredUsers = this.filterUsersOnSearch() } - const allUsers= this.state.allUsers.filter(user => user.id !== this.props.loggedInUser.id) + const allUsers = this.state.allUsers.filter(user => user.id !== this.props.loggedInUser.id) const { advancedSearchIsClicked, searchVal } = this.state return (
@@ -177,14 +187,14 @@ class AllUsers extends Component { {advancedSearchIsClicked ? "close" : "search options"}
- {advancedSearchIsClicked && } + {advancedSearchIsClicked && }
{searchVal ? ( this.renderSearchCards(filteredUsers) ) : ( - this.renderSearchCards(allUsers) - )} + this.renderSearchCards(allUsers) + )}
) diff --git a/src/components/CommentCard.js b/src/components/CommentCard.js index 0673609..c5ca54c 100644 --- a/src/components/CommentCard.js +++ b/src/components/CommentCard.js @@ -134,7 +134,7 @@ class CommentCard extends Component { )} - {user.cohort}-{user.cohortId} + {user.cohort.toUpperCase()}-{user.cohortId} {comment.code ? ( diff --git a/src/components/EditProfile.js b/src/components/EditProfile.js index 8db14ad..93a33a6 100644 --- a/src/components/EditProfile.js +++ b/src/components/EditProfile.js @@ -48,22 +48,22 @@ class EditProfile extends React.Component { event.preventDefault() this.setState({ isProfileSaved: true }) if ( - this.state.isWorkAdressEdited && + this.state.isWorkAdressEdited && !this.state.isUserDetailsEdited ) { this.getGeoCodeByAddress() - .then(result => { - const userWorkInfo = { - companyLower: this.state.loggedInUser.companyLower, - workInfo: { - address: this.state.address, - coordinates: result + .then(result => { + const userWorkInfo = { + company: this.state.loggedInUser.company, + workInfo: { + address: this.state.address, + coordinates: result + } } - } - this.updateUser(userWorkInfo) - }) + this.updateUser(userWorkInfo) + }) } else if ( - this.state.isWorkAdressEdited && + this.state.isWorkAdressEdited && this.state.isUserDetailsEdited ) { this.getGeoCodeByAddress() @@ -126,14 +126,14 @@ class EditProfile extends React.Component { onWorkAddressChange = (address) => { - const companyLower = address.split(',')[0].toLowerCase() + const company = address.split(',')[0].toLowerCase() this.setState({ isWorkAdressEdited: true, address, loggedInUser: { ...this.state.loggedInUser, - workInfo: {...this.state.workInfo, address}, - companyLower: companyLower, + workInfo: { ...this.state.workInfo, address }, + company: company } }) } @@ -146,8 +146,8 @@ class EditProfile extends React.Component { onChange: this.onWorkAddressChange, } const options = [ - { key: 'GH', text: 'GH', value: 'GH' }, - { key: 'FS', text: 'FS', value: 'FS' }, + { key: 'GH', text: 'GH', value: 'gh' }, + { key: 'FS', text: 'FS', value: 'fs' }, ] return (
@@ -187,13 +187,61 @@ class EditProfile extends React.Component { name="city" value={user.city} /> - - + State +// \ No newline at end of file diff --git a/src/components/PostCard.js b/src/components/PostCard.js index 17704ff..5248af6 100644 --- a/src/components/PostCard.js +++ b/src/components/PostCard.js @@ -56,7 +56,7 @@ class PostCard extends Component { )} - {user.cohort}-{user.cohortId} + {user.cohort.toUpperCase()}-{user.cohortId} {post.link ? (
diff --git a/src/components/SearchCard.js b/src/components/SearchCard.js index f8ecb7f..9c71817 100644 --- a/src/components/SearchCard.js +++ b/src/components/SearchCard.js @@ -35,7 +35,7 @@ class SearchCard extends Component { this.onUserNameClick(event, user)}>{user.firstName} {user.lastName} - {user.cohort} - {user.cohortId} + {user.cohort && user.cohort.toUpperCase()} - {user.cohortId}
diff --git a/src/components/UserProfile.js b/src/components/UserProfile.js index a014f89..35428c3 100644 --- a/src/components/UserProfile.js +++ b/src/components/UserProfile.js @@ -50,7 +50,7 @@ class UserProfile extends React.Component { null )} {user.cohort && user.cohortId ? ( -
{user.cohort} {user.cohortId}
+
{user.cohort.toUpperCase()} {user.cohortId}
) : ( null )} @@ -60,7 +60,7 @@ class UserProfile extends React.Component { null )} {user.city ? ( -
Lives in {user.city}, {user.state} {user.country}
+
Lives in {user.city}, {user.state.toUpperCase()} {user.country}
) : ( null )}