Advertisement
Guest User

Untitled

a guest
Apr 29th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. class Search extends Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. resultsArr: [],
  6. results: null
  7. };
  8. }
  9.  
  10. async componentDidMount() {
  11. await Axios.get(
  12. "http://localhost:8080/users/search?query=" +
  13. this.props.match.params.value,
  14. {
  15. headers: {
  16. token: localStorage.getItem("jwtToken")
  17. }
  18. }
  19. )
  20. .then(async res => {
  21. console.log("success from search");
  22. console.log(res.data);
  23. await this.setState({ resultsArr: res.data });
  24. const showResults = this.state.resultsArr.map(profile => {
  25. console.log("auth:");
  26. console.log(this.props.auth);
  27. return (
  28. <CSSTransition key={profile._id} timeout={500} classNames="scroll">
  29. <button
  30. type="button"
  31. className="list-group-item list-group-item-action"
  32. >
  33. <ProfileSearch
  34. key={profile._id}
  35. name={profile.name}
  36. usernmae={profile.screen_name}
  37. text={profile.bio}
  38. profile_image_url={profile.profile_image_url}
  39. />
  40. </button>
  41. </CSSTransition>
  42. );
  43. });
  44. this.setState({ results: showResults });
  45. })
  46. .catch(err => {
  47. console.log("failure from search", { ...err });
  48. });
  49. }
  50. render() {
  51. // this.getSearchResults();
  52. return (
  53. <div className="container-fluid">
  54. <div style={{ marginBottom: "1%" }}>
  55. <Nav />
  56. </div>
  57. <div className="container" style={{ width: "80%" }}>
  58. {this.state.resultsArr.length > 0 ? (
  59. <div className="list-group">
  60. <button className="list-group-item list-group-item-action active">
  61. Search Results
  62. </button>
  63. <TransitionGroup>{this.state.results}</TransitionGroup>
  64. </div>
  65. ) : (
  66. <div style={{ textAlign: "center", marginTop: "10%" }}>
  67. <FontAwesomeIcon
  68. icon={faBomb}
  69. size={"10x"}
  70. style={{ color: "black", textAlign: "center" }}
  71. />
  72. <h1 style={{ textAlign: "center", marginTop: "2%" }}>
  73. No results
  74. </h1>
  75. </div>
  76. )}
  77. </div>
  78. </div>
  79. );
  80. }
  81. }
  82. const mapStateToProps = state => ({
  83. auth: state.auth
  84. });
  85.  
  86. export default connect(mapStateToProps)(Search);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement