diff --git a/components/awtis/cheche-awtis.js b/components/awtis/cheche-awtis.js index 3176074..c4a7d65 100644 --- a/components/awtis/cheche-awtis.js +++ b/components/awtis/cheche-awtis.js @@ -1,6 +1,6 @@ 'use client' -import {useEffect, useState} from 'react' +import {useEffect, useState, useMemo} from 'react' import {useRouter} from 'next/navigation' import TextField from '@mui/material/TextField' import Autocomplete from '@mui/material/Autocomplete' @@ -49,6 +49,12 @@ export default function ChecheAwtis() { } }, [loading]) + const sortedOptions = useMemo(() => { + return [...options].sort((a, b) => + -b.firstLetter.localeCompare(a.firstLetter) + ); + }, [options]); + return ( -b.firstLetter.localeCompare(a.firstLetter))} - groupBy={option => option?.firstLetter} - getOptionLabel={option => option?.alias} - renderOption={(props, option) => ( -
  • - - {option?.alias} -
  • - )} - sx={{width: 300}} - renderInput={params => ( + options={sortedOptions} + groupBy={(option) => option?.firstLetter} + getOptionLabel={(option) => option?.alias} + renderOption={(props, option) => { + const {key, ...rest} = props; + + return ( +
  • + + {option?.alias} +
  • + ); + }} + sx={{ width: 300 }} + renderInput={(params) => ( - {loading ? : null} - {params.InputProps.endAdornment} - - ), + slotProps={{ + ...params.slotProps, + htmlInput: { ...params.slotProps.htmlInput }, }} /> )} onChange={(event, newValue) => { - router.push(`/awtis/${newValue.slug}`) - }} - onOpen={() => { - setOpen(true) - }} - onClose={() => { - setOpen(false) + router.push(`/awtis/${newValue.slug}`); }} + onOpen={() => setOpen(true)} + onClose={() => setOpen(false)} />
    - ) }