SearchPage.jsx 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React from 'react';
  2. import {
  3. CircularProgress,
  4. Container,
  5. IconButton,
  6. InputAdornment,
  7. TextField,
  8. Typography,
  9. useMediaQuery
  10. } from "@mui/material";
  11. import {useState} from "react";
  12. import SearchIcon from "@material-ui/icons/Search";
  13. import {connect} from "react-redux";
  14. import {actionFullGoodFind} from "../../actions/ActionGoodFind";
  15. import {actionSearchRemove} from "../../reducers/SearchReducer";
  16. import {ItemFound} from "./ItemFound";
  17. import {NotFound} from "./NotFound";
  18. const SearchPage = ({searchResult, onSearch, onSearchRemove}) => {
  19. const matches = useMediaQuery('(max-width:899px)')
  20. const [value, setValue] = useState('')
  21. const [click, setClick] = useState(false)
  22. return(
  23. <>
  24. <main
  25. style={{
  26. backgroundColor: "#f3f3f3",
  27. marginTop: '85px',
  28. padding: matches ? "20px 0" : "50px 0",
  29. minHeight: 'calc(100vh - (185px + 290px))'
  30. }}
  31. >
  32. <Container maxWidth="sm">
  33. <Typography
  34. variant='h5'
  35. fontFamily='sarif'
  36. letterSpacing='3px'
  37. marginBottom='30px'
  38. >
  39. WHAT YOU ARE LOOKING FOR?
  40. </Typography>
  41. <TextField
  42. color={'primary'}
  43. fullWidth
  44. variant="standard"
  45. value={value}
  46. placeholder="Start typing..."
  47. onChange={(event) => {
  48. setClick(false);
  49. setValue(event.target.value);
  50. onSearchRemove()}
  51. }
  52. InputProps={{
  53. sx: {
  54. padding: '10px',
  55. outline:'none',
  56. color: '#616161',
  57. fontWeight: '300',
  58. letterSpacing: '1px',
  59. marginBottom: '50px'},
  60. endAdornment: (
  61. <InputAdornment position="end">
  62. <IconButton onClick={() => {
  63. setClick(true);
  64. onSearchRemove();
  65. onSearch(value)}
  66. }>
  67. <SearchIcon />
  68. </IconButton>
  69. </InputAdornment>
  70. )
  71. }}
  72. />
  73. {(value !== '' && click) && (searchResult?.searchResult ?
  74. Object.values(searchResult.searchResult).length > 0 ?
  75. Object.values(searchResult.searchResult).map((item, index) =>
  76. <ItemFound key={index} item={item}/>
  77. )
  78. : <NotFound/>
  79. : <CircularProgress color="inherit"/>
  80. )}
  81. </Container>
  82. </main>
  83. </>
  84. )
  85. }
  86. const CSearchPage = connect(state => ({
  87. searchResult: state.search}),
  88. {
  89. onSearch: actionFullGoodFind,
  90. onSearchRemove: actionSearchRemove})
  91. (SearchPage)
  92. export default CSearchPage