app: Recherche ignore les accents

This commit is contained in:
Mattéo Delabre 2019-12-03 23:35:27 -05:00
parent 99a2d487f3
commit eea5e49a96
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
3 changed files with 21 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import React, {useState, useRef} from 'react';
import * as diacritics from 'diacritics';
/**
* Codes des touches du clavier par nom.
@ -12,6 +13,19 @@ const keys = Object.assign(Object.create(null), {
'down': 40,
});
/**
* Vérifie si un terme est similaire à un préfixe saisi.
*
* @param prefix Préfixe saisi.
* @param term Terme à vérifier.
* @return Vrai si le terme est considéré comme similaire au préfixe.
*/
const termMatchesPrefix = (prefix, {name}) =>
{
return diacritics.remove(name.toLowerCase())
.startsWith(diacritics.remove(prefix.toLowerCase()));
};
/**
* Zone de saisie des termes de recherche.
*
@ -141,9 +155,7 @@ const TermInput = ({terms, availableTerms, setTerms}) =>
)
)
// Filtre ceux dont le nom correspond à la saisie
.filter(({name}) =>
name.toLowerCase().startsWith(nextValue.toLowerCase())
)
.filter(termMatchesPrefix.bind(null, nextValue))
);
}
};

5
package-lock.json generated
View File

@ -2508,6 +2508,11 @@
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=",
"dev": true
},
"diacritics": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/diacritics/-/diacritics-1.3.0.tgz",
"integrity": "sha1-PvqHMj67hj5mls67AILUj/PW96E="
},
"diffie-hellman": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",

View File

@ -16,6 +16,7 @@
},
"dependencies": {
"@babel/runtime": "^7.7.4",
"diacritics": "^1.3.0",
"eslint": "^6.7.2",
"eslint-plugin-react": "^7.17.0",
"react": "^16.12.0",