Search.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { actionSearch } from "../actions/actionSearch";
  2. import { Link } from "react-router-dom";
  3. import { connect } from "react-redux";
  4. import { useState } from "react";
  5. import code from "../../src/code.png";
  6. import "./Main.css";
  7. const Search = ({ onSearch, snippets }) => {
  8. const [request, setRequest] = useState("");
  9. return (
  10. <>
  11. <Link to="/work">
  12. <div className="btn_block_back">
  13. <button className="btn_search">Back to Work Page</button>
  14. </div>
  15. </Link>
  16. <br />
  17. <br />
  18. <div>
  19. <input
  20. className="field_for_search"
  21. value={request}
  22. onChange={(e) => setRequest(e.target.value)}
  23. type="search"
  24. placeholder="Type name or description"
  25. aria-label="Search"
  26. />
  27. <br />
  28. <div className="btn_block_search">
  29. <button className="btn_search" onClick={() => onSearch(request)}>
  30. Search
  31. </button>
  32. </div>
  33. </div>
  34. <div className="snippet_block">
  35. {snippets?.map((key, index) => (
  36. <div key={key} className="snippet">
  37. <img src={code} alt="code"></img>
  38. <div className="block_content">
  39. <p>
  40. {`Name: ${snippets?.[index]?.title}` || "Project without name"}
  41. </p>
  42. <p>{`Description: ${snippets?.[index]?.description}` || ""}</p>
  43. <p>{`Owner: ${snippets?.[index]?.owner?.login}`}</p>
  44. <div className="btn_center">
  45. <Link to={"/project/" + snippets?.[index]?._id}>
  46. <button className="btn_search">Open project</button>
  47. </Link>
  48. </div>
  49. </div>
  50. </div>
  51. ))}
  52. </div>
  53. </>
  54. );
  55. };
  56. const ConnectFormSearch = connect(
  57. (state) => ({
  58. snippets: state?.p?.searchSnippet?.payload?.data?.SnippetFind,
  59. }),
  60. { onSearch: actionSearch }
  61. )(Search);
  62. export default ConnectFormSearch;