mirror of
https://github.com/immich-app/immich.git
synced 2024-12-25 10:43:13 +02:00
fix(web): whitespace in person name (#5401)
* fix(web): whitespace in person name * pr feedback
This commit is contained in:
parent
8b6a79ad9e
commit
b396e0eee3
@ -17,6 +17,7 @@
|
||||
import CircleIconButton from '../elements/buttons/circle-icon-button.svelte';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
|
||||
import { searchNameLocal } from '$lib/utils/person';
|
||||
|
||||
export let person: PersonResponseDto;
|
||||
let people: PersonResponseDto[] = [];
|
||||
@ -56,12 +57,7 @@
|
||||
}
|
||||
if (!force) {
|
||||
if (people.length < 20 && name.startsWith(searchWord)) {
|
||||
people = peopleCopy
|
||||
.filter((person: PersonResponseDto) => {
|
||||
const nameParts = person.name.split(' ');
|
||||
return nameParts.some((splitName) => splitName.toLowerCase().startsWith(name.toLowerCase()));
|
||||
})
|
||||
.slice(0, 10);
|
||||
people = searchNameLocal(name, peopleCopy, 10);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
32
web/src/lib/utils/person.ts
Normal file
32
web/src/lib/utils/person.ts
Normal 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);
|
||||
};
|
@ -35,6 +35,7 @@
|
||||
import LoadingSpinner from '$lib/components/shared-components/loading-spinner.svelte';
|
||||
import { mdiPlus, mdiDotsVertical, mdiArrowLeft } from '@mdi/js';
|
||||
import { isExternalUrl } from '$lib/utils/navigation';
|
||||
import { searchNameLocal } from '$lib/utils/person';
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
@ -110,17 +111,7 @@
|
||||
|
||||
$: {
|
||||
if (people) {
|
||||
suggestedPeople = !name
|
||||
? []
|
||||
: people
|
||||
.filter((person: PersonResponseDto) => {
|
||||
const nameParts = person.name.split(' ');
|
||||
return (
|
||||
nameParts.some((splitName) => splitName.toLowerCase().startsWith(name.toLowerCase())) &&
|
||||
person.id !== data.person.id
|
||||
);
|
||||
})
|
||||
.slice(0, 5);
|
||||
suggestedPeople = !name ? [] : searchNameLocal(name, people, 5, data.person.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user