SearchPage.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import {
  2. Box,
  3. CircularProgress,
  4. Container,
  5. IconButton,
  6. InputAdornment,
  7. TextField,
  8. Typography,
  9. useMediaQuery
  10. } from "@mui/material";
  11. import SearchIcon from "@material-ui/icons/Search";
  12. import {connect} from "react-redux";
  13. import {actionFullGoodFind} from "../actions/ActionGoodFind";
  14. import {useState} from "react";
  15. import {backURL} from "../actions/PathDB";
  16. import imgNotFound from "../img/catalog/imgNotFound.png";
  17. import Link from "react-router-dom/es/Link";
  18. import {actionSearchRemove} from "../reducers/SearchReducer";
  19. const NotFound = () => {
  20. return (
  21. <Typography
  22. textAlign='center'
  23. color='#000'
  24. letterSpacing='1px'
  25. variant='body1'
  26. >
  27. No results found
  28. </Typography>
  29. )
  30. }
  31. const ItemFound = ({item:{_id, name, price, images, description}}) => {
  32. return (
  33. <Link style={{textDecoration: 'none', display: 'flex', alignItems: 'center', marginBottom: '30px'}} to={`/good/${_id}`}>
  34. <Box width='60px' height='60px' borderRadius='10px' overflow='hidden' marginRight='60px' position='relative'>
  35. <img style={{position: 'absolute',top: '0', left: '0', width: '100%', height: '100%', objectFit: 'cover'}} src={images[0]?.url ? backURL + '/' + images[0]?.url : imgNotFound} alt={name}/>
  36. </Box>
  37. <Box sx={{display: 'flex', flexDirection:'column', justifyContent: 'space-between', alignItems:'flex-start'}}>
  38. <Typography
  39. color='#000'
  40. letterSpacing='1px'
  41. fontFamily='sarif'
  42. fontWeight='600'
  43. variant='h6'
  44. >
  45. {name}
  46. </Typography>
  47. <Typography
  48. letterSpacing='1px'
  49. variant='body1'
  50. fontWeight='300'
  51. color='#616161'
  52. margin='10px 0'
  53. >
  54. {description.length > 60 ? 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.' : description}
  55. </Typography>
  56. <Typography
  57. color='#000'
  58. letterSpacing='1px'
  59. variant='body1'
  60. fontWeight='600'
  61. >
  62. ${parseFloat(price).toFixed(2)}
  63. </Typography>
  64. </Box>
  65. </Link>
  66. )
  67. }
  68. const SearchPage = ({searchResult, onSearch, onSearchRemove}) => {
  69. const matches = useMediaQuery('(max-width:899px)')
  70. const [value, setValue] = useState('')
  71. const [click, setClick] = useState(false)
  72. return(
  73. <>
  74. <main style={{backgroundColor: "#f3f3f3", marginTop: '85px', padding: matches ? "20px 0" : "50px 0", minHeight: 'calc(100vh - (185px + 290px))'}}>
  75. <Container maxWidth="sm">
  76. <Typography
  77. variant='h5'
  78. fontFamily='sarif'
  79. letterSpacing='3px'
  80. marginBottom='30px'
  81. >
  82. WHAT YOU ARE LOOKING FOR?
  83. </Typography>
  84. <TextField
  85. color={'primary'}
  86. fullWidth
  87. variant="standard"
  88. value={value}
  89. placeholder="Start typing..."
  90. onChange={(event) => {setClick(false); setValue(event.target.value); onSearchRemove()}}
  91. InputProps={{
  92. sx: {padding: '10px', outline:'none', color: '#616161', fontWeight: '300', letterSpacing: '1px', marginBottom: '50px'},
  93. endAdornment: (
  94. <InputAdornment position="end">
  95. <IconButton onClick={() => {setClick(true); onSearchRemove(); onSearch(value)}}>
  96. <SearchIcon />
  97. </IconButton>
  98. </InputAdornment>
  99. )
  100. }}
  101. />
  102. {(value !== '' && click) && (searchResult?.searchResult ?
  103. Object.values(searchResult.searchResult).length > 0 ?
  104. Object.values(searchResult.searchResult).map(item => <ItemFound item={item}/>) : <NotFound/> :
  105. <CircularProgress color="inherit"/>
  106. )}
  107. </Container>
  108. </main>
  109. </>
  110. )
  111. }
  112. const CSearchPage = connect(state=>({searchResult: state.search}), {onSearch: actionFullGoodFind, onSearchRemove: actionSearchRemove})(SearchPage)
  113. export default CSearchPage
  114. // TODO MOBILE VERSION