|
1 | 1 | <script lang="ts">
|
2 |
| - import { maximumLengthSearchPeople, timeBeforeShowLoadingSpinner } from '$lib/constants'; |
| 2 | + import { timeBeforeShowLoadingSpinner } from '$lib/constants'; |
3 | 3 | import { photoViewer } from '$lib/stores/assets.store';
|
4 | 4 | import { getAssetThumbnailUrl, getPeopleThumbnailUrl } from '$lib/utils';
|
5 |
| - import { handleError } from '$lib/utils/handle-error'; |
6 |
| - import { getPersonNameWithHiddenValue, searchNameLocal } from '$lib/utils/person'; |
7 |
| - import { |
8 |
| - AssetTypeEnum, |
9 |
| - ThumbnailFormat, |
10 |
| - searchPerson, |
11 |
| - type AssetFaceResponseDto, |
12 |
| - type PersonResponseDto, |
13 |
| - } from '@immich/sdk'; |
| 5 | + import { getPersonNameWithHiddenValue } from '$lib/utils/person'; |
| 6 | + import { AssetTypeEnum, ThumbnailFormat, type AssetFaceResponseDto, type PersonResponseDto } from '@immich/sdk'; |
14 | 7 | import { mdiArrowLeftThin, mdiClose, mdiMagnify, mdiPlus } from '@mdi/js';
|
15 | 8 | import { createEventDispatcher } from 'svelte';
|
16 | 9 | import { linear } from 'svelte/easing';
|
17 | 10 | import { fly } from 'svelte/transition';
|
18 | 11 | import ImageThumbnail from '../assets/thumbnail/image-thumbnail.svelte';
|
19 | 12 | import Icon from '../elements/icon.svelte';
|
20 | 13 | import LoadingSpinner from '../shared-components/loading-spinner.svelte';
|
| 14 | + import SearchPeople from '$lib/components/faces-page/search-people.svelte'; |
21 | 15 |
|
22 | 16 | export let peopleWithFaces: AssetFaceResponseDto[];
|
23 | 17 | export let allPeople: PersonResponseDto[];
|
|
31 | 25 |
|
32 | 26 | // search people
|
33 | 27 | let searchedPeople: PersonResponseDto[] = [];
|
34 |
| - let searchedPeopleCopy: PersonResponseDto[] = []; |
35 |
| - let searchWord: string; |
36 | 28 | let searchFaces = false;
|
37 | 29 | let searchName = '';
|
38 | 30 |
|
|
116 | 108 | isShowLoadingNewPerson = false;
|
117 | 109 | dispatch('createPerson', newFeaturePhoto);
|
118 | 110 | };
|
119 |
| -
|
120 |
| - const searchPeople = async () => { |
121 |
| - if ((searchedPeople.length < maximumLengthSearchPeople && searchName.startsWith(searchWord)) || searchName === '') { |
122 |
| - return; |
123 |
| - } |
124 |
| - const timeout = setTimeout(() => (isShowLoadingSearch = true), timeBeforeShowLoadingSpinner); |
125 |
| - try { |
126 |
| - const data = await searchPerson({ name: searchName }); |
127 |
| - searchedPeople = data; |
128 |
| - searchedPeopleCopy = data; |
129 |
| - searchWord = searchName; |
130 |
| - } catch (error) { |
131 |
| - handleError(error, "Can't search people"); |
132 |
| - } finally { |
133 |
| - clearTimeout(timeout); |
134 |
| - } |
135 |
| -
|
136 |
| - isShowLoadingSearch = false; |
137 |
| - }; |
138 |
| -
|
139 |
| - $: { |
140 |
| - searchedPeople = searchNameLocal(searchName, searchedPeopleCopy, 20); |
141 |
| - } |
142 |
| -
|
143 |
| - const initInput = (element: HTMLInputElement) => { |
144 |
| - element.focus(); |
145 |
| - }; |
146 | 111 | </script>
|
147 | 112 |
|
148 | 113 | <section
|
|
200 | 165 | </div>
|
201 | 166 | </button>
|
202 | 167 | <div class="w-full flex">
|
203 |
| - <input |
204 |
| - class="w-full gap-2 bg-immich-bg dark:bg-immich-dark-bg" |
205 |
| - type="text" |
206 |
| - placeholder="Name or nickname" |
207 |
| - bind:value={searchName} |
208 |
| - on:input={searchPeople} |
209 |
| - use:initInput |
| 168 | + <SearchPeople |
| 169 | + type="input" |
| 170 | + bind:searchName |
| 171 | + bind:isSearching={isShowLoadingSearch} |
| 172 | + bind:searchedPeopleLocal={searchedPeople} |
210 | 173 | />
|
211 | 174 | {#if isShowLoadingSearch}
|
212 | 175 | <div>
|
|
0 commit comments