2020-12-13 23:20:07 +01:00
|
|
|
import {useState} from 'react'
|
|
|
|
|
import PropTypes from 'prop-types'
|
2020-12-15 08:23:32 +01:00
|
|
|
import union from 'lodash.union'
|
2020-12-13 23:20:07 +01:00
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
Divider,
|
|
|
|
|
FormControl,
|
|
|
|
|
InputAdornment,
|
|
|
|
|
InputBase,
|
|
|
|
|
makeStyles
|
|
|
|
|
} from '@material-ui/core'
|
|
|
|
|
|
|
|
|
|
import SearchIcon from '@material-ui/icons/Search'
|
|
|
|
|
|
|
|
|
|
import MizikLis from '../awtis/mizik-lis'
|
|
|
|
|
|
|
|
|
|
const useStyles = makeStyles(theme => ({
|
|
|
|
|
toolbar: theme.mixins.toolbar,
|
|
|
|
|
list: {
|
|
|
|
|
marginBottom: '6em'
|
|
|
|
|
},
|
|
|
|
|
form: {
|
|
|
|
|
marginLeft: theme.spacing(1)
|
|
|
|
|
},
|
|
|
|
|
text: {
|
|
|
|
|
marginBottom: '0.5em'
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
|
2020-12-18 22:08:34 +01:00
|
|
|
const getMizikFiltered = (teks, filter) => {
|
|
|
|
|
if (teks) {
|
|
|
|
|
const filteredTitre = teks.filter(({tit}) => {
|
|
|
|
|
return tit.toLowerCase().includes(filter.toLowerCase())
|
2020-12-15 08:23:32 +01:00
|
|
|
})
|
|
|
|
|
|
2020-12-18 22:08:34 +01:00
|
|
|
const filteredAlias = teks.filter(({awtis}) => {
|
2020-12-15 08:23:32 +01:00
|
|
|
const aliasLis = awtis.map(({alias}) => alias).join()
|
|
|
|
|
return aliasLis.toLowerCase().includes(filter.toLowerCase())
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return union(filteredTitre, filteredAlias)
|
2020-12-13 23:20:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-18 22:21:53 +01:00
|
|
|
export default function DrawerBar({meteEsMobilOuve, teks, anTeks}) {
|
2020-12-18 22:08:34 +01:00
|
|
|
const slug = anTeks ? anTeks.slug : null
|
2020-12-13 23:20:07 +01:00
|
|
|
const classes = useStyles()
|
|
|
|
|
|
|
|
|
|
const [search, setSearch] = useState('')
|
2020-12-18 22:08:34 +01:00
|
|
|
const [slugTeksChwazi, meteSlugTeksChwazi] = useState(slug)
|
2020-12-13 23:20:07 +01:00
|
|
|
|
2020-12-18 22:08:34 +01:00
|
|
|
const mizikFiltered = getMizikFiltered(teks, search)
|
2020-12-13 23:20:07 +01:00
|
|
|
|
|
|
|
|
const handleSearch = event => {
|
|
|
|
|
event.preventDefault()
|
|
|
|
|
const value = event.target.value
|
|
|
|
|
setSearch(value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className='search'>
|
|
|
|
|
<FormControl className={classes.form}>
|
|
|
|
|
<InputBase
|
|
|
|
|
className={classes.toolbar}
|
2020-12-15 08:23:32 +01:00
|
|
|
placeholder='Chèché...'
|
2020-12-13 23:20:07 +01:00
|
|
|
startAdornment={
|
|
|
|
|
<InputAdornment position='start'>
|
|
|
|
|
<SearchIcon />
|
|
|
|
|
</InputAdornment>
|
|
|
|
|
}
|
|
|
|
|
value={search}
|
|
|
|
|
onChange={handleSearch}
|
|
|
|
|
/>
|
|
|
|
|
</FormControl>
|
|
|
|
|
<Divider />
|
|
|
|
|
<div className={classes.list}>
|
|
|
|
|
<MizikLis
|
2020-12-18 22:08:34 +01:00
|
|
|
niAwtis
|
2020-12-18 22:21:53 +01:00
|
|
|
meteEsMobilOuve={meteEsMobilOuve}
|
2020-12-18 22:08:34 +01:00
|
|
|
teks={mizikFiltered}
|
|
|
|
|
slugTeksChwazi={slugTeksChwazi}
|
|
|
|
|
meteSlugTeksChwazi={meteSlugTeksChwazi}
|
2020-12-13 23:20:07 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawerBar.propTypes = {
|
2020-12-18 22:21:53 +01:00
|
|
|
meteEsMobilOuve: PropTypes.func,
|
2020-12-18 22:08:34 +01:00
|
|
|
teks: PropTypes.array.isRequired,
|
|
|
|
|
anTeks: PropTypes.object
|
2020-12-13 23:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawerBar.defaultProps = {
|
2020-12-18 22:21:53 +01:00
|
|
|
meteEsMobilOuve: null,
|
2020-12-18 22:08:34 +01:00
|
|
|
anTeks: null
|
2020-12-13 23:20:07 +01:00
|
|
|
}
|