search.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Link } from "react-router-dom";
  2. import { actionSearch } from "../actions/actionSearch";
  3. import { connect } from "react-redux";
  4. import { useState } from "react";
  5. const Search = ({onSearch , snippets}) => {
  6. const [request, setRequest] = useState('');
  7. return (
  8. <>
  9. <Link to="/">
  10. <button className="float-left btn-secondary d-inline-block mt-2 ml-2">
  11. Back to Main Page
  12. </button>
  13. </Link>
  14. <br/>
  15. <br/>
  16. <div style ={{textAlign: "center" , alignItems:"center", justifyContent:'center'}}>
  17. <input
  18. value={request}
  19. onChange={(e) => setRequest(e.target.value)}
  20. className="form-control d-inline-block w-50 mt-2"
  21. type="search"
  22. placeholder="Name of project"
  23. aria-label="Search"
  24. />
  25. <br/>
  26. <button
  27. className="btn btn-outline-success border-success mt-4 mb-4" onClick = {() => onSearch(request)}
  28. >
  29. Search
  30. </button>
  31. </div>
  32. {snippets?.map((key, index) => (
  33. <div style={{ textAlign: "center", alignItems: "center" }}>
  34. <div className="card w-50 ml-auto mr-auto mt-3 mb-5" style = {{boxShadow:'0px 5px 10px 2px rgba(34, 60, 80, 0.2)'}}>
  35. <div className="card-body" style={{ textAlign: "center" }}>
  36. <h3 className="card-title mb-4 text-info">
  37. {snippets?.[index]?.title || "Project without name"}
  38. </h3>
  39. <p className="card-text">
  40. <span className="text-muted">Description</span>&nbsp;
  41. {snippets?.[index]?.description || ""}
  42. </p>
  43. <p>{`Owner: ${snippets?.[index]?.owner?.login}`}</p>
  44. <Link to={"/project/" + snippets?.[index]?._id}>
  45. <button className="btn btn-primary mt-3">Open project</button>
  46. </Link>
  47. </div>
  48. </div>
  49. </div>
  50. ))}
  51. </>
  52. )
  53. };
  54. const CSearch = connect(state => ({snippets:state?.promise?.searchSnippet?.payload?.data?.SnippetFind}) , {onSearch:actionSearch})(Search)
  55. export default CSearch;