search.js 2.3 KB

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