normalize polish signs

This commit is contained in:
maciekglowacki 2020-10-22 23:04:00 +02:00
parent 148156fdca
commit 770a5f09d3
2 changed files with 15 additions and 4 deletions

View File

@ -60,19 +60,30 @@ interface DropdownProps {
export const Dropdown = ({ clearInput, handleClearInput }: DropdownProps) => { export const Dropdown = ({ clearInput, handleClearInput }: DropdownProps) => {
const classes = useStyles(); const classes = useStyles();
const [open, setOpen] = React.useState(false); const [open, setOpen] = useState(false);
const [input, setInput] = useState<string>(''); const [input, setInput] = useState('');
//courses - choosenCourses //courses - choosenCourses
const [filteredCourses, setFilteredCourses] = useState<Array<Course>>([]); const [filteredCourses, setFilteredCourses] = useState<Array<Course>>([]);
const { courses, basket, addToBasket } = useContext(coursesContext)!; const { courses, basket, addToBasket } = useContext(coursesContext)!;
useEffect(() => { useEffect(() => {
const filterCourses = (input: string) => { const filterCourses = (input: string) => {
const choosenCoursesNames = basket.map(({ name }) => name.trim()); const choosenCoursesNames = basket.map(({ name }) => name.trim());
const filteredCourses = courses.filter( const filteredCourses = courses.filter(
({ name }) => name.toLowerCase().includes(input.toLowerCase()) && !choosenCoursesNames.includes(name), ({ name }) =>
name
.toLowerCase()
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.includes(
input
.toLowerCase()
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, ''),
) && !choosenCoursesNames.includes(name),
); );
setFilteredCourses(filteredCourses); setFilteredCourses(filteredCourses);
}; };

View File

@ -107,7 +107,7 @@ export default function ({ handleTransfer }: TopbarProps) {
<TopbarInputIconStyled alt="close" src={CloseIcon} onClick={handleClearInput} /> <TopbarInputIconStyled alt="close" src={CloseIcon} onClick={handleClearInput} />
</TopbarInputStyled> </TopbarInputStyled>
<TopbarIconBox> <TopbarIconBox>
<TopbarIcon alt="transfer" src={Transfer} onClick={handleTransfer} /> {/* <TopbarIcon alt="transfer" src={Transfer} onClick={handleTransfer} /> */}
<TopbarIcon alt="change_language" src={isPolish ? UK : PL} onClick={onLangChange} /> <TopbarIcon alt="change_language" src={isPolish ? UK : PL} onClick={onLangChange} />
<TopbarIcon alt="profile" src={User} onClick={handleProfile} /> <TopbarIcon alt="profile" src={User} onClick={handleProfile} />
<Profile anchorEl={anchorEl} handleClose={handleClose} /> <Profile anchorEl={anchorEl} handleClose={handleClose} />