fix(web): whitespace in person name (#5401)

* fix(web): whitespace in person name

* pr feedback
This commit is contained in:
martin 2023-11-30 04:08:54 +01:00 committed by GitHub
parent 8b6a79ad9e
commit b396e0eee3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 17 deletions

View file

@ -0,0 +1,32 @@
import type { PersonResponseDto } from '@api';
export const searchNameLocal = (
name: string,
people: PersonResponseDto[],
slice: number,
personId?: string,
): PersonResponseDto[] => {
return name.indexOf(' ') >= 0
? people
.filter((person: PersonResponseDto) => {
if (personId) {
return person.name.toLowerCase().startsWith(name.toLowerCase()) && person.id !== personId;
} else {
return person.name.toLowerCase().startsWith(name.toLowerCase());
}
})
.slice(0, slice)
: people
.filter((person: PersonResponseDto) => {
const nameParts = person.name.split(' ');
if (personId) {
return (
nameParts.some((splitName) => splitName.toLowerCase().startsWith(name.toLowerCase())) &&
person.id !== personId
);
} else {
return nameParts.some((splitName) => splitName.toLowerCase().startsWith(name.toLowerCase()));
}
})
.slice(0, slice);
};