-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from sledilnik/mobile-map-alert-empty-list
feat: ✨ add snackbar alert on mobile in map view
- Loading branch information
Showing
2 changed files
with
80 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { forwardRef, useEffect, useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { useTranslation } from 'react-i18next'; | ||
import { styled } from '@mui/material/styles'; | ||
|
||
import MuiSnackbar from '@mui/material/Snackbar'; | ||
import MuiAlert from '@mui/material/Alert'; | ||
|
||
const Snackbar = styled(MuiSnackbar)(({ theme }) => ({ | ||
'&.MuiSnackbar-anchorOriginTopCenter': { | ||
top: '96px', | ||
}, | ||
|
||
[theme.breakpoints.up('md')]: { | ||
display: 'none', | ||
}, | ||
})); | ||
|
||
const Alert = forwardRef((props, ref) => ( | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
<MuiAlert elevation={6} ref={ref} {...props} /> | ||
)); | ||
|
||
const MapOnlySnackbar = function MapOnlySnackbar({ noResults }) { | ||
const { t } = useTranslation(); | ||
const [open, setOpen] = useState(noResults); | ||
|
||
const handleClose = (event, reason) => { | ||
if (reason === 'clickaway') { | ||
return; | ||
} | ||
|
||
setOpen(false); | ||
}; | ||
|
||
useEffect(() => { | ||
if (!noResults) { | ||
setOpen(false); | ||
} | ||
|
||
if (noResults) { | ||
setOpen(true); | ||
} | ||
}, [noResults]); | ||
|
||
return ( | ||
<Snackbar | ||
open={open} | ||
autoHideDuration={6000} | ||
onClose={handleClose} | ||
anchorOrigin={{ vertical: 'top', horizontal: 'center' }} | ||
> | ||
<Alert onClose={handleClose} severity="info" sx={{ width: '100%' }}> | ||
{t('noResults')} | ||
</Alert> | ||
</Snackbar> | ||
); | ||
}; | ||
|
||
MapOnlySnackbar.propTypes = { | ||
noResults: PropTypes.bool.isRequired, | ||
}; | ||
export default MapOnlySnackbar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters