|
| 1 | +import { Box, Typography, Chip, TextField } from '@mui/material'; |
| 2 | + |
| 3 | +import { BaseAutocomplete } from '@ui'; |
| 4 | +import type { IExerciseSelectProps } from './types'; |
| 5 | +import { useGetAllExercises } from './queries'; |
| 6 | + |
| 7 | +export const ExerciseSelect = ({ |
| 8 | + onSelect, |
| 9 | + disabled, |
| 10 | +}: IExerciseSelectProps) => { |
| 11 | + const { data: exercises = [], isLoading } = useGetAllExercises(); |
| 12 | + return ( |
| 13 | + <BaseAutocomplete |
| 14 | + disabled={disabled || isLoading} |
| 15 | + options={exercises} |
| 16 | + getOptionLabel={(option) => option.name} |
| 17 | + filterOptions={(options, state) => { |
| 18 | + const inputValue = state.inputValue.toLowerCase(); |
| 19 | + return options.filter( |
| 20 | + (option) => |
| 21 | + option.name.toLowerCase().includes(inputValue) || |
| 22 | + option.muscleGroup.toLowerCase().includes(inputValue), |
| 23 | + ); |
| 24 | + }} |
| 25 | + renderOption={(props, option) => { |
| 26 | + const { key, ...otherProps } = props; |
| 27 | + return ( |
| 28 | + <li |
| 29 | + key={key} |
| 30 | + {...otherProps} |
| 31 | + style={{ borderBottom: '1px solid #ffffff10' }} |
| 32 | + > |
| 33 | + <Box |
| 34 | + display="flex" |
| 35 | + justifyContent="space-between" |
| 36 | + width="100%" |
| 37 | + alignItems="center" |
| 38 | + > |
| 39 | + <Typography variant="body1" color="textPrimary"> |
| 40 | + {option.name} |
| 41 | + </Typography> |
| 42 | + <Chip |
| 43 | + label={option.muscleGroup} |
| 44 | + size="small" |
| 45 | + sx={{ |
| 46 | + backgroundColor: '#8CEF0D20', |
| 47 | + color: '#8CEF0D', |
| 48 | + fontSize: '10px', |
| 49 | + height: '20px', |
| 50 | + }} |
| 51 | + /> |
| 52 | + </Box> |
| 53 | + </li> |
| 54 | + ); |
| 55 | + }} |
| 56 | + onChange={(_, value) => { |
| 57 | + if (value) { |
| 58 | + onSelect(value); |
| 59 | + } |
| 60 | + }} |
| 61 | + loading={isLoading} |
| 62 | + itemType="Find Exercise" |
| 63 | + renderInput={(params) => <TextField {...params} />} |
| 64 | + /> |
| 65 | + ); |
| 66 | +}; |
0 commit comments