Fix Autocomplete in ChecheAwtis component
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import {useEffect, useState} from 'react'
|
import {useEffect, useState, useMemo} from 'react'
|
||||||
import {useRouter} from 'next/navigation'
|
import {useRouter} from 'next/navigation'
|
||||||
import TextField from '@mui/material/TextField'
|
import TextField from '@mui/material/TextField'
|
||||||
import Autocomplete from '@mui/material/Autocomplete'
|
import Autocomplete from '@mui/material/Autocomplete'
|
||||||
@@ -49,6 +49,12 @@ export default function ChecheAwtis() {
|
|||||||
}
|
}
|
||||||
}, [loading])
|
}, [loading])
|
||||||
|
|
||||||
|
const sortedOptions = useMemo(() => {
|
||||||
|
return [...options].sort((a, b) =>
|
||||||
|
-b.firstLetter.localeCompare(a.firstLetter)
|
||||||
|
);
|
||||||
|
}, [options]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container
|
<Container
|
||||||
sx={{ display: 'flex', justifyContent: 'center', marginBottom: 3 }}
|
sx={{ display: 'flex', justifyContent: 'center', marginBottom: 3 }}
|
||||||
@@ -62,42 +68,40 @@ export default function ChecheAwtis() {
|
|||||||
loadingText='Chargement...'
|
loadingText='Chargement...'
|
||||||
noOptionsText='Aucun résultat'
|
noOptionsText='Aucun résultat'
|
||||||
id='cheche-awtis'
|
id='cheche-awtis'
|
||||||
options={options.sort((a, b) => -b.firstLetter.localeCompare(a.firstLetter))}
|
options={sortedOptions}
|
||||||
groupBy={option => option?.firstLetter}
|
groupBy={(option) => option?.firstLetter}
|
||||||
getOptionLabel={option => option?.alias}
|
getOptionLabel={(option) => option?.alias}
|
||||||
renderOption={(props, option) => (
|
renderOption={(props, option) => {
|
||||||
<li {...props}>
|
const {key, ...rest} = props;
|
||||||
<Avatar style={{marginRight: 8}} alt={option?.alias} src={`${IMAGE_URL}${option?.photo?.data?.attributes?.formats?.thumbnail?.url}`} />
|
|
||||||
|
return (
|
||||||
|
<li key={key} {...rest}>
|
||||||
|
<Avatar
|
||||||
|
style={{ marginRight: 8 }}
|
||||||
|
alt={option?.alias}
|
||||||
|
src={`${IMAGE_URL}${option?.photo?.formats?.thumbnail?.url}`}
|
||||||
|
/>
|
||||||
{option?.alias}
|
{option?.alias}
|
||||||
</li>
|
</li>
|
||||||
)}
|
);
|
||||||
sx={{width: 300}}
|
}}
|
||||||
renderInput={params => (
|
sx={{ width: 300 }}
|
||||||
|
renderInput={(params) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...params}
|
{...params}
|
||||||
label='Rechercher un artiste'
|
label='Rechercher un artiste'
|
||||||
InputProps={{
|
slotProps={{
|
||||||
...params.InputProps,
|
...params.slotProps,
|
||||||
endAdornment: (
|
htmlInput: { ...params.slotProps.htmlInput },
|
||||||
<>
|
|
||||||
{loading ? <CircularProgress color='primary' size={20} /> : null}
|
|
||||||
{params.InputProps.endAdornment}
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
onChange={(event, newValue) => {
|
onChange={(event, newValue) => {
|
||||||
router.push(`/awtis/${newValue.slug}`)
|
router.push(`/awtis/${newValue.slug}`);
|
||||||
}}
|
|
||||||
onOpen={() => {
|
|
||||||
setOpen(true)
|
|
||||||
}}
|
|
||||||
onClose={() => {
|
|
||||||
setOpen(false)
|
|
||||||
}}
|
}}
|
||||||
|
onOpen={() => setOpen(true)}
|
||||||
|
onClose={() => setOpen(false)}
|
||||||
/>
|
/>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user