1
0
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:
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

@ -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;
}
}

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);
};

View File

@ -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);
}
}