Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1.  
  2. import React, { Component } from 'react';
  3. import logo from './logo1.png';
  4. import './App.css';
  5. import axios from "axios";
  6. import Venue from './components/Venue';
  7.  
  8.  
  9. const API_DEFAULT = "https://api.foursquare.com/v2/venues/explore?client_secret=ISV2BFBDZIZL1WNG00D13F4CSLRXIARM0SXTSUU0KZSWWKMG&client_id=KVQIDLMIY4F0BIBEPQNSVQUSABBANRITCWD2ZL2MDPEGH1FM&v=20161101";
  10.  
  11. class App extends Component {
  12. state = {
  13. near:"",
  14. limit: 3,
  15. list: [],
  16. wish: ""
  17. }
  18.  
  19.  
  20. render() {
  21. let printlist = this.state.list.map (
  22. (value, index)=> {
  23. return <Venue value={value} key={index} />;
  24. }
  25. )
  26.  
  27. return (
  28. <div className="App container">
  29. <div className="text-center">
  30. <h2 className="d-inline welcome">Welcome to "CityLife" </h2>
  31. <h5 className="recommend">Find out the best spots!</h5>
  32. </div>
  33. <div className="row">
  34. <div className="col l6 inputdiv push-l2 center-align">
  35. <input onChange={this.placeChanged} type="text" className="form-control d-inline" placeholder="City: " value={this.state.near}/>
  36. <select className="form-control selection" onChange={this.wishChanged}>
  37. <option value="food">Food</option>
  38. <option value="drinks">Drinks</option>
  39. <option value="coffee">Coffee</option>
  40. <option value="shops">Shops</option>
  41. <option value="arts">Arts</option>
  42. <option value="outdoors">Outdoors</option>
  43. <option value="trending">Trending</option>
  44. </select>
  45. <div className="left-align">
  46. <button type="button" className=" btn-floating btn-large scale-transition waves-effect waves-light"onClick={this.searchHandler}> Search </button>
  47. </div>
  48. </div>
  49. <div className="row">
  50. <div className="col l6 inputdiv center-align">
  51. <img src={logo} className="App-logo " alt="logo" />
  52. </div>
  53. </div>
  54. </div>
  55.  
  56. <div className="list-group col l9 ">
  57. <div className="d-flex flex-wrap w-100 justify-content-between list-group-item">
  58. {printlist}
  59. </div>
  60. <div className="align-right">
  61. <button type="button" className="btn-floating btn-large scale-transition waves-effect waves-light" onClick={this.moreResults} value={this.state.limit}> + </button>
  62. </div>
  63. </div>
  64.  
  65. </div>
  66. );
  67. }
  68.  
  69.  
  70. placeChanged = event => {
  71. this.setState({
  72. near: event.target.value
  73. })
  74. };
  75.  
  76. wishChanged = event => {
  77. this.setState({
  78. wish: event.target.value
  79. } );
  80. };
  81.  
  82. moreResults = event => {
  83. this.setState({
  84. limit: +event.target.value + 3
  85. }, this.getResults );
  86. };
  87.  
  88.  
  89.  
  90. searchHandler = () => {
  91. this.getResults();
  92. }
  93.  
  94.  
  95. getResults=()=> {
  96.  
  97. let near = this.state.near;
  98. let limit = this.state.limit;
  99. let wish = this.state.wish;
  100. // console.log(wish);
  101. axios.get(API_DEFAULT+ '&limit='+ limit +'&near='+ near +'&section='+wish)
  102. .then(res=> {
  103. console.log( res)
  104. let items = res.data.response.groups[0].items;
  105. console.log(items);
  106. this.setState({
  107. list:items
  108. })
  109. })
  110. .catch(err=> {
  111. console.log(err)
  112. })
  113.  
  114. }
  115.  
  116. componentDidMount(){
  117. this.getResults();
  118. }
  119. }
  120.  
  121. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement