2023-12-05 16:43:15 +01:00
|
|
|
<script lang="ts">
|
2024-02-14 14:09:49 +01:00
|
|
|
import { maximumLengthSearchPeople, timeBeforeShowLoadingSpinner } from '$lib/constants';
|
2023-12-05 16:43:15 +01:00
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
|
|
|
import { searchNameLocal } from '$lib/utils/person';
|
2024-02-14 15:38:57 +01:00
|
|
|
import { searchPerson, type PersonResponseDto } from '@immich/sdk';
|
2024-02-14 14:09:49 +01:00
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
import FaceThumbnail from './face-thumbnail.svelte';
|
2024-02-22 15:04:43 +01:00
|
|
|
import SearchBar from '../elements/search-bar.svelte';
|
2023-12-05 16:43:15 +01:00
|
|
|
|
|
|
|
export let screenHeight: number;
|
|
|
|
export let people: PersonResponseDto[];
|
|
|
|
export let peopleCopy: PersonResponseDto[];
|
|
|
|
export let unselectedPeople: PersonResponseDto[];
|
|
|
|
|
|
|
|
let name = '';
|
|
|
|
let searchWord: string;
|
|
|
|
let isSearchingPeople = false;
|
|
|
|
|
|
|
|
let dispatch = createEventDispatcher<{
|
|
|
|
select: PersonResponseDto;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
$: {
|
|
|
|
people = peopleCopy.filter(
|
|
|
|
(person) => !unselectedPeople.some((unselectedPerson) => unselectedPerson.id === person.id),
|
|
|
|
);
|
2023-12-08 15:21:29 +01:00
|
|
|
if (name) {
|
2024-01-28 01:54:31 +01:00
|
|
|
people = searchNameLocal(name, people, maximumLengthSearchPeople);
|
2023-12-08 15:21:29 +01:00
|
|
|
}
|
2023-12-05 16:43:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const searchPeople = async (force: boolean) => {
|
|
|
|
if (name === '') {
|
|
|
|
people = peopleCopy;
|
|
|
|
return;
|
|
|
|
}
|
2024-02-02 04:18:00 +01:00
|
|
|
if (!force && people.length < maximumLengthSearchPeople && name.startsWith(searchWord)) {
|
|
|
|
return;
|
2023-12-05 16:43:15 +01:00
|
|
|
}
|
|
|
|
|
2024-01-28 01:54:31 +01:00
|
|
|
const timeout = setTimeout(() => (isSearchingPeople = true), timeBeforeShowLoadingSpinner);
|
2023-12-05 16:43:15 +01:00
|
|
|
try {
|
2024-02-14 14:09:49 +01:00
|
|
|
people = await searchPerson({ name });
|
2023-12-05 16:43:15 +01:00
|
|
|
searchWord = name;
|
|
|
|
} catch (error) {
|
|
|
|
handleError(error, "Can't search people");
|
|
|
|
} finally {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
isSearchingPeople = false;
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
2024-01-28 01:54:31 +01:00
|
|
|
<div class=" w-40 sm:w-48 md:w-96 h-14 mb-8">
|
|
|
|
<SearchBar
|
|
|
|
bind:name
|
2024-02-22 15:04:43 +01:00
|
|
|
isSearching={isSearchingPeople}
|
|
|
|
placeholder="Search people"
|
2024-01-28 01:54:31 +01:00
|
|
|
on:reset={() => {
|
|
|
|
people = peopleCopy;
|
|
|
|
}}
|
|
|
|
on:search={({ detail }) => searchPeople(detail.force ?? false)}
|
2023-12-05 16:43:15 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div
|
|
|
|
class="immich-scrollbar overflow-y-auto rounded-3xl bg-gray-200 p-10 dark:bg-immich-dark-gray"
|
|
|
|
style:max-height={screenHeight - 400 + 'px'}
|
|
|
|
>
|
|
|
|
<div class="grid-col-2 grid gap-8 md:grid-cols-3 lg:grid-cols-6 xl:grid-cols-8 2xl:grid-cols-10">
|
|
|
|
{#each people as person (person.id)}
|
|
|
|
<FaceThumbnail
|
|
|
|
{person}
|
|
|
|
on:click={() => {
|
|
|
|
dispatch('select', person);
|
|
|
|
}}
|
|
|
|
circle
|
|
|
|
border
|
|
|
|
selectable
|
|
|
|
/>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
</div>
|