-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from seckboy/profile-refactor
add saved pins and searches to profile
- Loading branch information
Showing
8 changed files
with
205 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {h, Component} from 'preact'; | ||
import style from './style'; | ||
import {makeRequest, token} from "../../js/server-requests-utils"; | ||
import {SAVED_PINS_PATH} from '../../../config'; | ||
|
||
export default class SavedPinsCard extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { | ||
user: {}, | ||
savedPins: [], | ||
}; | ||
this.getSavedPins = this.getSavedPins.bind(this); | ||
this.displayPins = this.displayPins.bind(this); | ||
} | ||
|
||
componentWillMount() { | ||
this.setState({user: this.props.user}); | ||
this.getSavedPins(); | ||
} | ||
|
||
displayPins(savedPins) { | ||
let pins = []; | ||
savedPins.map( pin => { | ||
pins.push(<div>{pin.place_id}</div>); | ||
}); | ||
if(pins.length == 0) pins.push(<div>No saved pins</div>); | ||
this.setState({pins: pins}); | ||
} | ||
|
||
getSavedPins() { | ||
makeRequest('GET', SAVED_PINS_PATH) | ||
.then(function (response) { | ||
this.displayPins(response.data.savedPins); | ||
}.bind(this)) | ||
.catch(function (error) { | ||
if (error.response === undefined) { | ||
this.setState({savedPins: error}); | ||
} else { | ||
this.setState({savedPins: error.response.data}); | ||
} | ||
}.bind(this)); | ||
} | ||
|
||
render({}, {user, pins}) { | ||
|
||
|
||
return ( | ||
<div class={style.savedPinsCard}> | ||
|
||
<span id={style.savedPinsCardTitle}>Saved Pins</span><br/> | ||
|
||
|
||
<div class={style.savedPinsContainer}>{pins}</div> | ||
|
||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.savedPinsCard { | ||
border-radius: 3px; | ||
border-width: 2px; | ||
border-style: groove; | ||
margin-bottom: 10px; | ||
padding-left: 5px; | ||
} | ||
|
||
#savedPinsCardTitle { | ||
display: block; | ||
font-size: 1em; | ||
font-weight: bold; | ||
text-align: center; | ||
color: purple; | ||
margin: 0 auto; | ||
} | ||
|
||
.savedPinsContainer{ | ||
text-align: center; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {h, Component} from 'preact'; | ||
import style from './style'; | ||
import {makeRequest, token} from "../../js/server-requests-utils"; | ||
import {SEARCH_HISTORY_PATH} from '../../../config'; | ||
|
||
export default class SearchHistoryCard extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { | ||
user: {}, | ||
searchHistory: [], | ||
}; | ||
this.getSearchHistory = this.getSearchHistory.bind(this); | ||
this.displayHistory = this.displayHistory.bind(this); | ||
} | ||
|
||
componentWillMount() { | ||
this.setState({user: this.props.user}); | ||
this.getSearchHistory(); | ||
} | ||
|
||
displayHistory(searchHistory) { | ||
let histories = []; | ||
searchHistory.map( search => { | ||
histories.push(<div>{search.query}</div>); | ||
}); | ||
if(histories.length == 0) histories.push(<div>No saved searches</div>); | ||
this.setState({histories: histories}); | ||
} | ||
|
||
getSearchHistory() { | ||
makeRequest('GET', SEARCH_HISTORY_PATH) | ||
.then(function (response) { | ||
this.displayHistory(response.data.searchHistory); | ||
}.bind(this)) | ||
.catch(function (error) { | ||
if (error.response === undefined) { | ||
this.setState({searchHistory: error}); | ||
} else { | ||
this.setState({searchHistory: error.response.data}); | ||
} | ||
}.bind(this)); | ||
} | ||
|
||
render({}, {user, histories}) { | ||
|
||
|
||
return ( | ||
<div class={style.searchHistoryCard}> | ||
|
||
<span id={style.searchHistoryCardTitle}>Search History</span><br/> | ||
|
||
|
||
<div class={style.searchHistoriesContainer}>{histories}</div> | ||
|
||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.searchHistoryCard { | ||
border-radius: 3px; | ||
border-width: 2px; | ||
border-style: groove; | ||
margin-bottom: 10px; | ||
padding-left: 5px; | ||
} | ||
|
||
#searchHistoryCardTitle { | ||
display: block; | ||
font-size: 1em; | ||
font-weight: bold; | ||
text-align: center; | ||
color: purple; | ||
margin: 0 auto; | ||
} | ||
|
||
.searchHistoriesContainer{ | ||
text-align: center; | ||
} | ||
|
Oops, something went wrong.