SearchPage.jsx 3.5 KB

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