Search.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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>{`Name: ${snippets?.[index]?.title}` || "Project without name"}</p>
  40. <p>{`Description: ${snippets?.[index]?.description}` || ""}</p>
  41. <p>{`Owner: ${snippets?.[index]?.owner?.login}`}</p>
  42. <div className='btn_center'>
  43. <Link to={"/project/" + snippets?.[index]?._id}>
  44. <button className='btn_search'>Open project</button>
  45. </Link>
  46. </div>
  47. </div>
  48. </div>
  49. ))}
  50. </div>
  51. </>
  52. );
  53. };
  54. const ConnectFormSearch = connect(
  55. state => ({
  56. snippets: state?.p?.searchSnippet?.payload?.data?.SnippetFind,
  57. }),
  58. { onSearch: actionSearch },
  59. )(Search);
  60. export default ConnectFormSearch;