mirror of
https://github.com/immich-app/immich.git
synced 2025-01-19 18:26:46 +01:00
refactor(web): search people (#9082)
* refactor: search people * fix: test * fix: timeout * fix: callbacks * fix: simplify * remove unused var * refactor: rename file * fix: focus when deleting last character --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com> Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
parent
72ce81f0c2
commit
5722c830ff
12 changed files with 207 additions and 267 deletions
|
@ -100,7 +100,7 @@
|
||||||
|
|
||||||
<!-- Search Albums -->
|
<!-- Search Albums -->
|
||||||
<div class="hidden xl:block h-10 xl:w-60 2xl:w-80">
|
<div class="hidden xl:block h-10 xl:w-60 2xl:w-80">
|
||||||
<SearchBar placeholder="Search albums" bind:name={searchQuery} isSearching={false} />
|
<SearchBar placeholder="Search albums" bind:name={searchQuery} showLoadingSpinner={false} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Create Album -->
|
<!-- Create Album -->
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
export let name: string;
|
export let name: string;
|
||||||
export let roundedBottom = true;
|
export let roundedBottom = true;
|
||||||
export let isSearching: boolean;
|
export let showLoadingSpinner: boolean;
|
||||||
export let placeholder: string;
|
export let placeholder: string;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher<{ search: SearchOptions; reset: void }>();
|
const dispatch = createEventDispatcher<{ search: SearchOptions; reset: void }>();
|
||||||
|
@ -16,6 +16,12 @@
|
||||||
name = '';
|
name = '';
|
||||||
dispatch('reset');
|
dispatch('reset');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSearch = (event: KeyboardEvent) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
dispatch('search', { force: true });
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
@ -33,9 +39,10 @@
|
||||||
type="text"
|
type="text"
|
||||||
{placeholder}
|
{placeholder}
|
||||||
bind:value={name}
|
bind:value={name}
|
||||||
|
on:keydown={handleSearch}
|
||||||
on:input={() => dispatch('search', { force: false })}
|
on:input={() => dispatch('search', { force: false })}
|
||||||
/>
|
/>
|
||||||
{#if isSearching}
|
{#if showLoadingSpinner}
|
||||||
<div class="flex place-items-center">
|
<div class="flex place-items-center">
|
||||||
<LoadingSpinner />
|
<LoadingSpinner />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,16 +1,9 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { maximumLengthSearchPeople, timeBeforeShowLoadingSpinner } from '$lib/constants';
|
import { timeBeforeShowLoadingSpinner } from '$lib/constants';
|
||||||
import { photoViewer } from '$lib/stores/assets.store';
|
import { photoViewer } from '$lib/stores/assets.store';
|
||||||
import { getAssetThumbnailUrl, getPeopleThumbnailUrl } from '$lib/utils';
|
import { getAssetThumbnailUrl, getPeopleThumbnailUrl } from '$lib/utils';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { getPersonNameWithHiddenValue } from '$lib/utils/person';
|
||||||
import { getPersonNameWithHiddenValue, searchNameLocal } from '$lib/utils/person';
|
import { AssetTypeEnum, ThumbnailFormat, type AssetFaceResponseDto, type PersonResponseDto } from '@immich/sdk';
|
||||||
import {
|
|
||||||
AssetTypeEnum,
|
|
||||||
ThumbnailFormat,
|
|
||||||
searchPerson,
|
|
||||||
type AssetFaceResponseDto,
|
|
||||||
type PersonResponseDto,
|
|
||||||
} from '@immich/sdk';
|
|
||||||
import { mdiArrowLeftThin, mdiClose, mdiMagnify, mdiPlus } from '@mdi/js';
|
import { mdiArrowLeftThin, mdiClose, mdiMagnify, mdiPlus } from '@mdi/js';
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
import { linear } from 'svelte/easing';
|
import { linear } from 'svelte/easing';
|
||||||
|
@ -18,6 +11,7 @@
|
||||||
import ImageThumbnail from '../assets/thumbnail/image-thumbnail.svelte';
|
import ImageThumbnail from '../assets/thumbnail/image-thumbnail.svelte';
|
||||||
import Icon from '../elements/icon.svelte';
|
import Icon from '../elements/icon.svelte';
|
||||||
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
|
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
|
||||||
|
import SearchPeople from '$lib/components/faces-page/people-search.svelte';
|
||||||
|
|
||||||
export let peopleWithFaces: AssetFaceResponseDto[];
|
export let peopleWithFaces: AssetFaceResponseDto[];
|
||||||
export let allPeople: PersonResponseDto[];
|
export let allPeople: PersonResponseDto[];
|
||||||
|
@ -31,11 +25,11 @@
|
||||||
|
|
||||||
// search people
|
// search people
|
||||||
let searchedPeople: PersonResponseDto[] = [];
|
let searchedPeople: PersonResponseDto[] = [];
|
||||||
let searchedPeopleCopy: PersonResponseDto[] = [];
|
|
||||||
let searchWord: string;
|
|
||||||
let searchFaces = false;
|
let searchFaces = false;
|
||||||
let searchName = '';
|
let searchName = '';
|
||||||
|
|
||||||
|
$: showPeople = searchName ? searchedPeople : allPeople.filter((person) => !person.isHidden);
|
||||||
|
|
||||||
const dispatch = createEventDispatcher<{
|
const dispatch = createEventDispatcher<{
|
||||||
close: void;
|
close: void;
|
||||||
createPerson: string | null;
|
createPerson: string | null;
|
||||||
|
@ -116,33 +110,6 @@
|
||||||
isShowLoadingNewPerson = false;
|
isShowLoadingNewPerson = false;
|
||||||
dispatch('createPerson', newFeaturePhoto);
|
dispatch('createPerson', newFeaturePhoto);
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchPeople = async () => {
|
|
||||||
if ((searchedPeople.length < maximumLengthSearchPeople && searchName.startsWith(searchWord)) || searchName === '') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const timeout = setTimeout(() => (isShowLoadingSearch = true), timeBeforeShowLoadingSpinner);
|
|
||||||
try {
|
|
||||||
const data = await searchPerson({ name: searchName });
|
|
||||||
searchedPeople = data;
|
|
||||||
searchedPeopleCopy = data;
|
|
||||||
searchWord = searchName;
|
|
||||||
} catch (error) {
|
|
||||||
handleError(error, "Can't search people");
|
|
||||||
} finally {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
isShowLoadingSearch = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
$: {
|
|
||||||
searchedPeople = searchNameLocal(searchName, searchedPeopleCopy, 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
const initInput = (element: HTMLInputElement) => {
|
|
||||||
element.focus();
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<section
|
<section
|
||||||
|
@ -200,13 +167,11 @@
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
<div class="w-full flex">
|
<div class="w-full flex">
|
||||||
<input
|
<SearchPeople
|
||||||
class="w-full gap-2 bg-immich-bg dark:bg-immich-dark-bg"
|
type="input"
|
||||||
type="text"
|
bind:searchName
|
||||||
placeholder="Name or nickname"
|
bind:showLoadingSpinner={isShowLoadingSearch}
|
||||||
bind:value={searchName}
|
bind:searchedPeopleLocal={searchedPeople}
|
||||||
on:input={searchPeople}
|
|
||||||
use:initInput
|
|
||||||
/>
|
/>
|
||||||
{#if isShowLoadingSearch}
|
{#if isShowLoadingSearch}
|
||||||
<div>
|
<div>
|
||||||
|
@ -227,8 +192,7 @@
|
||||||
<div class="px-4 py-4 text-sm">
|
<div class="px-4 py-4 text-sm">
|
||||||
<h2 class="mb-8 mt-4 uppercase">All people</h2>
|
<h2 class="mb-8 mt-4 uppercase">All people</h2>
|
||||||
<div class="immich-scrollbar mt-4 flex flex-wrap gap-2 overflow-y-auto">
|
<div class="immich-scrollbar mt-4 flex flex-wrap gap-2 overflow-y-auto">
|
||||||
{#if searchName == ''}
|
{#each showPeople as person (person.id)}
|
||||||
{#each allPeople as person (person.id)}
|
|
||||||
{#if person.id !== editedPerson.id}
|
{#if person.id !== editedPerson.id}
|
||||||
<div class="w-fit">
|
<div class="w-fit">
|
||||||
<button class="w-[90px]" on:click={() => dispatch('reassign', person)}>
|
<button class="w-[90px]" on:click={() => dispatch('reassign', person)}>
|
||||||
|
@ -253,30 +217,6 @@
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
|
||||||
{#each searchedPeople as person (person.id)}
|
|
||||||
{#if person.id !== editedPerson.id}
|
|
||||||
<div class="w-fit">
|
|
||||||
<button class="w-[90px]" on:click={() => dispatch('reassign', person)}>
|
|
||||||
<div class="relative">
|
|
||||||
<ImageThumbnail
|
|
||||||
curve
|
|
||||||
shadow
|
|
||||||
url={getPeopleThumbnailUrl(person.id)}
|
|
||||||
altText={getPersonNameWithHiddenValue(person.name, person.isHidden)}
|
|
||||||
title={getPersonNameWithHiddenValue(person.name, person.isHidden)}
|
|
||||||
widthStyle="90px"
|
|
||||||
heightStyle="90px"
|
|
||||||
thumbhash={null}
|
|
||||||
hidden={person.isHidden}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<p class="mt-1 truncate font-medium" title={person.name}>{person.name}</p>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
{/each}
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -1,29 +1,23 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { type PersonResponseDto } from '@immich/sdk';
|
import { type PersonResponseDto } from '@immich/sdk';
|
||||||
import { createEventDispatcher, onMount } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
import ImageThumbnail from '../assets/thumbnail/image-thumbnail.svelte';
|
import ImageThumbnail from '../assets/thumbnail/image-thumbnail.svelte';
|
||||||
import Button from '../elements/buttons/button.svelte';
|
import Button from '../elements/buttons/button.svelte';
|
||||||
|
import SearchPeople from '$lib/components/faces-page/people-search.svelte';
|
||||||
|
|
||||||
export let person: PersonResponseDto;
|
export let person: PersonResponseDto;
|
||||||
export let name: string;
|
export let name: string;
|
||||||
export let suggestedPeople = false;
|
export let suggestedPeople: PersonResponseDto[];
|
||||||
export let thumbnailData: string;
|
export let thumbnailData: string;
|
||||||
|
export let isSearchingPeople: boolean;
|
||||||
let inputElement: HTMLInputElement;
|
|
||||||
|
|
||||||
const dispatch = createEventDispatcher<{
|
const dispatch = createEventDispatcher<{
|
||||||
change: string;
|
change: string;
|
||||||
cancel: void;
|
|
||||||
input: void;
|
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
inputElement.focus();
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="flex w-full h-14 place-items-center {suggestedPeople
|
class="flex w-full h-14 place-items-center {suggestedPeople.length > 0
|
||||||
? 'rounded-t-lg dark:border-immich-dark-gray'
|
? 'rounded-t-lg dark:border-immich-dark-gray'
|
||||||
: 'rounded-lg'} bg-gray-100 p-2 dark:bg-gray-700"
|
: 'rounded-lg'} bg-gray-100 p-2 dark:bg-gray-700"
|
||||||
>
|
>
|
||||||
|
@ -33,13 +27,13 @@
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
on:submit|preventDefault={() => dispatch('change', name)}
|
on:submit|preventDefault={() => dispatch('change', name)}
|
||||||
>
|
>
|
||||||
<input
|
<SearchPeople
|
||||||
class="w-full gap-2 bg-gray-100 dark:bg-gray-700 dark:text-white"
|
bind:searchName={name}
|
||||||
type="text"
|
bind:searchedPeopleLocal={suggestedPeople}
|
||||||
placeholder="New name or nickname"
|
type="input"
|
||||||
bind:value={name}
|
numberPeopleToSearch={5}
|
||||||
bind:this={inputElement}
|
inputClass="w-full gap-2 bg-gray-100 dark:bg-gray-700 dark:text-white"
|
||||||
on:input={() => dispatch('input')}
|
bind:showLoadingSpinner={isSearchingPeople}
|
||||||
/>
|
/>
|
||||||
<Button size="sm" type="submit">Done</Button>
|
<Button size="sm" type="submit">Done</Button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { maximumLengthSearchPeople, timeBeforeShowLoadingSpinner } from '$lib/constants';
|
import { type PersonResponseDto } from '@immich/sdk';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
|
||||||
import { searchNameLocal } from '$lib/utils/person';
|
|
||||||
import { searchPerson, type PersonResponseDto } from '@immich/sdk';
|
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
import FaceThumbnail from './face-thumbnail.svelte';
|
import FaceThumbnail from './face-thumbnail.svelte';
|
||||||
import SearchBar from '../elements/search-bar.svelte';
|
import SearchPeople from '$lib/components/faces-page/people-search.svelte';
|
||||||
|
|
||||||
export let screenHeight: number;
|
export let screenHeight: number;
|
||||||
export let people: PersonResponseDto[];
|
export let people: PersonResponseDto[];
|
||||||
|
@ -13,54 +10,26 @@
|
||||||
export let unselectedPeople: PersonResponseDto[];
|
export let unselectedPeople: PersonResponseDto[];
|
||||||
|
|
||||||
let name = '';
|
let name = '';
|
||||||
let searchWord: string;
|
let showPeople: PersonResponseDto[];
|
||||||
let isSearchingPeople = false;
|
|
||||||
|
|
||||||
let dispatch = createEventDispatcher<{
|
let dispatch = createEventDispatcher<{
|
||||||
select: PersonResponseDto;
|
select: PersonResponseDto;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
people = peopleCopy.filter(
|
showPeople = people.filter(
|
||||||
(person) => !unselectedPeople.some((unselectedPerson) => unselectedPerson.id === person.id),
|
(person) => !unselectedPeople.some((unselectedPerson) => unselectedPerson.id === person.id),
|
||||||
);
|
);
|
||||||
if (name) {
|
|
||||||
people = searchNameLocal(name, people, maximumLengthSearchPeople);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const searchPeople = async (force: boolean) => {
|
|
||||||
if (name === '') {
|
|
||||||
people = peopleCopy;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!force && people.length < maximumLengthSearchPeople && name.startsWith(searchWord)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeout = setTimeout(() => (isSearchingPeople = true), timeBeforeShowLoadingSpinner);
|
|
||||||
try {
|
|
||||||
people = await searchPerson({ name });
|
|
||||||
searchWord = name;
|
|
||||||
} catch (error) {
|
|
||||||
handleError(error, "Can't search people");
|
|
||||||
} finally {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
isSearchingPeople = false;
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class=" w-40 sm:w-48 md:w-96 h-14 mb-8">
|
<div class=" w-40 sm:w-48 md:w-96 h-14 mb-8">
|
||||||
<SearchBar
|
<SearchPeople
|
||||||
bind:name
|
type="searchBar"
|
||||||
isSearching={isSearchingPeople}
|
|
||||||
placeholder="Search people"
|
placeholder="Search people"
|
||||||
on:reset={() => {
|
bind:searchName={name}
|
||||||
people = peopleCopy;
|
bind:searchedPeopleLocal={people}
|
||||||
}}
|
onReset={() => (people = peopleCopy)}
|
||||||
on:search={({ detail }) => searchPeople(detail.force ?? false)}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -69,7 +38,7 @@
|
||||||
style:max-height={screenHeight - 400 + 'px'}
|
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">
|
<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)}
|
{#each showPeople as person (person.id)}
|
||||||
<FaceThumbnail
|
<FaceThumbnail
|
||||||
{person}
|
{person}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
|
|
100
web/src/lib/components/faces-page/people-search.svelte
Normal file
100
web/src/lib/components/faces-page/people-search.svelte
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import SearchBar from '$lib/components/elements/search-bar.svelte';
|
||||||
|
import { maximumLengthSearchPeople, timeBeforeShowLoadingSpinner } from '$lib/constants';
|
||||||
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
|
import { searchNameLocal } from '$lib/utils/person';
|
||||||
|
import { searchPerson, type PersonResponseDto } from '@immich/sdk';
|
||||||
|
|
||||||
|
export let searchName: string;
|
||||||
|
export let searchedPeopleLocal: PersonResponseDto[];
|
||||||
|
export let type: 'searchBar' | 'input';
|
||||||
|
export let numberPeopleToSearch: number = maximumLengthSearchPeople;
|
||||||
|
export let inputClass: string = 'w-full gap-2 bg-immich-bg dark:bg-immich-dark-bg';
|
||||||
|
export let showLoadingSpinner: boolean = false;
|
||||||
|
export let placeholder: string = 'Name or nickname';
|
||||||
|
export let onReset = () => {};
|
||||||
|
export let onSearch = () => {};
|
||||||
|
|
||||||
|
let searchedPeople: PersonResponseDto[] = [];
|
||||||
|
let searchWord: string;
|
||||||
|
let abortController: AbortController | null = null;
|
||||||
|
let timeout: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
|
const search = () => {
|
||||||
|
searchedPeopleLocal = searchNameLocal(searchName, searchedPeople, numberPeopleToSearch);
|
||||||
|
};
|
||||||
|
|
||||||
|
const reset = () => {
|
||||||
|
searchedPeopleLocal = [];
|
||||||
|
cancelPreviousRequest();
|
||||||
|
onReset();
|
||||||
|
};
|
||||||
|
|
||||||
|
const cancelPreviousRequest = () => {
|
||||||
|
if (abortController) {
|
||||||
|
abortController.abort();
|
||||||
|
abortController = null;
|
||||||
|
}
|
||||||
|
if (timeout) {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export let handleSearch = async (force?: boolean, name?: string) => {
|
||||||
|
searchName = name ?? searchName;
|
||||||
|
onSearch();
|
||||||
|
if (searchName === '') {
|
||||||
|
reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!force && searchedPeople.length < maximumLengthSearchPeople && searchName.startsWith(searchWord)) {
|
||||||
|
search();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cancelPreviousRequest();
|
||||||
|
abortController = new AbortController();
|
||||||
|
timeout = setTimeout(() => (showLoadingSpinner = true), timeBeforeShowLoadingSpinner);
|
||||||
|
try {
|
||||||
|
const data = await searchPerson({ name: searchName }, { signal: abortController?.signal });
|
||||||
|
searchedPeople = data;
|
||||||
|
searchWord = searchName;
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error, "Can't search people");
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = null;
|
||||||
|
abortController = null;
|
||||||
|
showLoadingSpinner = false;
|
||||||
|
search();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const initInput = (element: HTMLInputElement) => {
|
||||||
|
element.focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleReset = () => {
|
||||||
|
reset();
|
||||||
|
onReset();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if type === 'searchBar'}
|
||||||
|
<SearchBar
|
||||||
|
bind:name={searchName}
|
||||||
|
{showLoadingSpinner}
|
||||||
|
{placeholder}
|
||||||
|
on:reset={handleReset}
|
||||||
|
on:search={({ detail }) => handleSearch(detail.force ?? false)}
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<input
|
||||||
|
class={inputClass}
|
||||||
|
type="text"
|
||||||
|
{placeholder}
|
||||||
|
bind:value={searchName}
|
||||||
|
on:input={() => handleSearch(false)}
|
||||||
|
use:initInput
|
||||||
|
/>
|
||||||
|
{/if}
|
|
@ -23,7 +23,7 @@
|
||||||
let suggestedPlaces: PlacesResponseDto[] = [];
|
let suggestedPlaces: PlacesResponseDto[] = [];
|
||||||
let searchWord: string;
|
let searchWord: string;
|
||||||
let latestSearchTimeout: number;
|
let latestSearchTimeout: number;
|
||||||
let showSpinner = false;
|
let showLoadingSpinner = false;
|
||||||
let suggestionContainer: HTMLDivElement;
|
let suggestionContainer: HTMLDivElement;
|
||||||
let hideSuggestion = false;
|
let hideSuggestion = false;
|
||||||
let addClipMapMarker: (long: number, lat: number) => void;
|
let addClipMapMarker: (long: number, lat: number) => void;
|
||||||
|
@ -74,14 +74,14 @@
|
||||||
if (latestSearchTimeout) {
|
if (latestSearchTimeout) {
|
||||||
clearTimeout(latestSearchTimeout);
|
clearTimeout(latestSearchTimeout);
|
||||||
}
|
}
|
||||||
showSpinner = true;
|
showLoadingSpinner = true;
|
||||||
const searchTimeout = window.setTimeout(() => {
|
const searchTimeout = window.setTimeout(() => {
|
||||||
searchPlaces({ name: searchWord })
|
searchPlaces({ name: searchWord })
|
||||||
.then((searchResult) => {
|
.then((searchResult) => {
|
||||||
// skip result when a newer search is happening
|
// skip result when a newer search is happening
|
||||||
if (latestSearchTimeout === searchTimeout) {
|
if (latestSearchTimeout === searchTimeout) {
|
||||||
places = searchResult;
|
places = searchResult;
|
||||||
showSpinner = false;
|
showLoadingSpinner = false;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
@ -89,7 +89,7 @@
|
||||||
if (latestSearchTimeout === searchTimeout) {
|
if (latestSearchTimeout === searchTimeout) {
|
||||||
places = [];
|
places = [];
|
||||||
handleError(error, "Can't search places");
|
handleError(error, "Can't search places");
|
||||||
showSpinner = false;
|
showLoadingSpinner = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, timeDebounceOnSearch);
|
}, timeDebounceOnSearch);
|
||||||
|
@ -121,7 +121,7 @@
|
||||||
<SearchBar
|
<SearchBar
|
||||||
placeholder="Search places"
|
placeholder="Search places"
|
||||||
bind:name={searchWord}
|
bind:name={searchWord}
|
||||||
isSearching={showSpinner}
|
{showLoadingSpinner}
|
||||||
on:reset={() => {
|
on:reset={() => {
|
||||||
suggestedPlaces = [];
|
suggestedPlaces = [];
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
<div id="people-selection" class="-mb-4">
|
<div id="people-selection" class="-mb-4">
|
||||||
<div class="flex items-center w-full justify-between gap-6">
|
<div class="flex items-center w-full justify-between gap-6">
|
||||||
<p class="immich-form-label py-3">PEOPLE</p>
|
<p class="immich-form-label py-3">PEOPLE</p>
|
||||||
<SearchBar bind:name placeholder="Filter people" isSearching={false} />
|
<SearchBar bind:name placeholder="Filter people" showLoadingSpinner={false} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex -mx-1 max-h-64 gap-1 mt-2 flex-wrap overflow-y-auto immich-scrollbar">
|
<div class="flex -mx-1 max-h-64 gap-1 mt-2 flex-wrap overflow-y-auto immich-scrollbar">
|
||||||
|
|
|
@ -81,6 +81,6 @@ export function navigate<T extends Route>(change: T): Promise<void> {
|
||||||
export const clearQueryParam = async (queryParam: string, url: URL) => {
|
export const clearQueryParam = async (queryParam: string, url: URL) => {
|
||||||
if (url.searchParams.has(queryParam)) {
|
if (url.searchParams.has(queryParam)) {
|
||||||
url.searchParams.delete(queryParam);
|
url.searchParams.delete(queryParam);
|
||||||
await goto(url);
|
await goto(url, { keepFocus: true });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-60">
|
<div class="w-60">
|
||||||
<SearchBar placeholder="Search albums" bind:name={searchQuery} isSearching={false} />
|
<SearchBar placeholder="Search albums" bind:name={searchQuery} showLoadingSpinner={false} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
import Icon from '$lib/components/elements/icon.svelte';
|
import Icon from '$lib/components/elements/icon.svelte';
|
||||||
import MergeSuggestionModal from '$lib/components/faces-page/merge-suggestion-modal.svelte';
|
import MergeSuggestionModal from '$lib/components/faces-page/merge-suggestion-modal.svelte';
|
||||||
import PeopleCard from '$lib/components/faces-page/people-card.svelte';
|
import PeopleCard from '$lib/components/faces-page/people-card.svelte';
|
||||||
import SearchBar from '$lib/components/elements/search-bar.svelte';
|
|
||||||
import SetBirthDateModal from '$lib/components/faces-page/set-birth-date-modal.svelte';
|
import SetBirthDateModal from '$lib/components/faces-page/set-birth-date-modal.svelte';
|
||||||
import ShowHide from '$lib/components/faces-page/show-hide.svelte';
|
import ShowHide from '$lib/components/faces-page/show-hide.svelte';
|
||||||
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
|
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
|
||||||
|
@ -15,16 +14,9 @@
|
||||||
notificationController,
|
notificationController,
|
||||||
NotificationType,
|
NotificationType,
|
||||||
} from '$lib/components/shared-components/notification/notification';
|
} from '$lib/components/shared-components/notification/notification';
|
||||||
import {
|
import { ActionQueryParameterValue, AppRoute, QueryParameter } from '$lib/constants';
|
||||||
ActionQueryParameterValue,
|
|
||||||
AppRoute,
|
|
||||||
maximumLengthSearchPeople,
|
|
||||||
QueryParameter,
|
|
||||||
timeBeforeShowLoadingSpinner,
|
|
||||||
} from '$lib/constants';
|
|
||||||
import { getPeopleThumbnailUrl } from '$lib/utils';
|
import { getPeopleThumbnailUrl } from '$lib/utils';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import { searchNameLocal } from '$lib/utils/person';
|
|
||||||
import { shortcut } from '$lib/utils/shortcut';
|
import { shortcut } from '$lib/utils/shortcut';
|
||||||
import {
|
import {
|
||||||
getPerson,
|
getPerson,
|
||||||
|
@ -40,6 +32,7 @@
|
||||||
import type { PageData } from './$types';
|
import type { PageData } from './$types';
|
||||||
import { locale } from '$lib/stores/preferences.store';
|
import { locale } from '$lib/stores/preferences.store';
|
||||||
import { clearQueryParam } from '$lib/utils/navigation';
|
import { clearQueryParam } from '$lib/utils/navigation';
|
||||||
|
import SearchPeople from '$lib/components/faces-page/people-search.svelte';
|
||||||
import LinkButton from '$lib/components/elements/buttons/link-button.svelte';
|
import LinkButton from '$lib/components/elements/buttons/link-button.svelte';
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
|
@ -52,10 +45,7 @@
|
||||||
let initialHiddenValues: Record<string, boolean> = {};
|
let initialHiddenValues: Record<string, boolean> = {};
|
||||||
let eyeColorMap: Record<string, 'black' | 'white'> = {};
|
let eyeColorMap: Record<string, 'black' | 'white'> = {};
|
||||||
|
|
||||||
let searchedPeople: PersonResponseDto[] = [];
|
|
||||||
let searchName = '';
|
let searchName = '';
|
||||||
let searchWord: string;
|
|
||||||
let isSearchingPeople = false;
|
|
||||||
|
|
||||||
let showLoadingSpinner = false;
|
let showLoadingSpinner = false;
|
||||||
let toggleVisibility = false;
|
let toggleVisibility = false;
|
||||||
|
@ -68,29 +58,31 @@
|
||||||
let personMerge2: PersonResponseDto;
|
let personMerge2: PersonResponseDto;
|
||||||
let potentialMergePeople: PersonResponseDto[] = [];
|
let potentialMergePeople: PersonResponseDto[] = [];
|
||||||
let edittingPerson: PersonResponseDto | null = null;
|
let edittingPerson: PersonResponseDto | null = null;
|
||||||
|
let searchedPeopleLocal: PersonResponseDto[] = [];
|
||||||
|
let handleSearchPeople: (force?: boolean, name?: string) => Promise<void>;
|
||||||
|
|
||||||
let innerHeight: number;
|
let innerHeight: number;
|
||||||
|
|
||||||
for (const person of people) {
|
for (const person of people) {
|
||||||
initialHiddenValues[person.id] = person.isHidden;
|
initialHiddenValues[person.id] = person.isHidden;
|
||||||
}
|
}
|
||||||
|
$: showPeople = searchName ? searchedPeopleLocal : people.filter((person) => !person.isHidden);
|
||||||
$: searchedPeopleLocal = searchName ? searchNameLocal(searchName, searchedPeople, maximumLengthSearchPeople) : [];
|
|
||||||
|
|
||||||
$: countVisiblePeople = countTotalPeople - countHiddenPeople;
|
$: countVisiblePeople = countTotalPeople - countHiddenPeople;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const getSearchedPeople = $page.url.searchParams.get(QueryParameter.SEARCHED_PEOPLE);
|
const getSearchedPeople = $page.url.searchParams.get(QueryParameter.SEARCHED_PEOPLE);
|
||||||
if (getSearchedPeople) {
|
if (getSearchedPeople) {
|
||||||
searchName = getSearchedPeople;
|
searchName = getSearchedPeople;
|
||||||
await handleSearchPeople(true);
|
await handleSearchPeople(true, searchName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSearch = async (force: boolean) => {
|
const handleSearch = async () => {
|
||||||
|
const getSearchedPeople = $page.url.searchParams.get(QueryParameter.SEARCHED_PEOPLE);
|
||||||
|
if (getSearchedPeople !== searchName) {
|
||||||
$page.url.searchParams.set(QueryParameter.SEARCHED_PEOPLE, searchName);
|
$page.url.searchParams.set(QueryParameter.SEARCHED_PEOPLE, searchName);
|
||||||
await goto($page.url, { keepFocus: true });
|
await goto($page.url, { keepFocus: true });
|
||||||
await handleSearchPeople(force);
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCloseClick = () => {
|
const handleCloseClick = () => {
|
||||||
|
@ -278,28 +270,6 @@
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSearchPeople = async (force: boolean) => {
|
|
||||||
if (searchName === '') {
|
|
||||||
await clearQueryParam(QueryParameter.SEARCHED_PEOPLE, $page.url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!force && people.length < maximumLengthSearchPeople && searchName.startsWith(searchWord)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeout = setTimeout(() => (isSearchingPeople = true), timeBeforeShowLoadingSpinner);
|
|
||||||
try {
|
|
||||||
searchedPeople = await searchPerson({ name: searchName, withHidden: false });
|
|
||||||
searchWord = searchName;
|
|
||||||
} catch (error) {
|
|
||||||
handleError(error, "Can't search people");
|
|
||||||
} finally {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
isSearchingPeople = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const submitNameChange = async () => {
|
const submitNameChange = async () => {
|
||||||
potentialMergePeople = [];
|
potentialMergePeople = [];
|
||||||
showChangeNameModal = false;
|
showChangeNameModal = false;
|
||||||
|
@ -393,7 +363,6 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const onResetSearchBar = async () => {
|
const onResetSearchBar = async () => {
|
||||||
searchedPeople = [];
|
|
||||||
await clearQueryParam(QueryParameter.SEARCHED_PEOPLE, $page.url);
|
await clearQueryParam(QueryParameter.SEARCHED_PEOPLE, $page.url);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -420,12 +389,14 @@
|
||||||
<div class="flex gap-2 items-center justify-center">
|
<div class="flex gap-2 items-center justify-center">
|
||||||
<div class="hidden sm:block">
|
<div class="hidden sm:block">
|
||||||
<div class="w-40 lg:w-80 h-10">
|
<div class="w-40 lg:w-80 h-10">
|
||||||
<SearchBar
|
<SearchPeople
|
||||||
bind:name={searchName}
|
type="searchBar"
|
||||||
isSearching={isSearchingPeople}
|
|
||||||
placeholder="Search people"
|
placeholder="Search people"
|
||||||
on:reset={onResetSearchBar}
|
onReset={onResetSearchBar}
|
||||||
on:search={({ detail }) => handleSearch(detail.force ?? false)}
|
onSearch={handleSearch}
|
||||||
|
bind:searchName
|
||||||
|
bind:searchedPeopleLocal
|
||||||
|
bind:handleSearch={handleSearchPeople}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -441,8 +412,7 @@
|
||||||
|
|
||||||
{#if countVisiblePeople > 0 && (!searchName || searchedPeopleLocal.length > 0)}
|
{#if countVisiblePeople > 0 && (!searchName || searchedPeopleLocal.length > 0)}
|
||||||
<div class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 xl:grid-cols-7 2xl:grid-cols-9 gap-1">
|
<div class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 xl:grid-cols-7 2xl:grid-cols-9 gap-1">
|
||||||
{#if searchName}
|
{#each showPeople as person, index (person.id)}
|
||||||
{#each searchedPeopleLocal as person, index (person.id)}
|
|
||||||
<PeopleCard
|
<PeopleCard
|
||||||
{person}
|
{person}
|
||||||
preload={index < 20}
|
preload={index < 20}
|
||||||
|
@ -452,20 +422,6 @@
|
||||||
on:hide-person={() => handleHidePerson(person)}
|
on:hide-person={() => handleHidePerson(person)}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
|
||||||
{#each people as person, index (person.id)}
|
|
||||||
{#if !person.isHidden}
|
|
||||||
<PeopleCard
|
|
||||||
{person}
|
|
||||||
preload={index < 20}
|
|
||||||
on:change-name={() => handleChangeName(person)}
|
|
||||||
on:set-birth-date={() => handleSetBirthDate(person)}
|
|
||||||
on:merge-people={() => handleMergePeople(person)}
|
|
||||||
on:hide-person={() => handleHidePerson(person)}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
{/each}
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="flex min-h-[calc(66vh_-_11rem)] w-full place-content-center items-center dark:text-white">
|
<div class="flex min-h-[calc(66vh_-_11rem)] w-full place-content-center items-center dark:text-white">
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
NotificationType,
|
NotificationType,
|
||||||
notificationController,
|
notificationController,
|
||||||
} from '$lib/components/shared-components/notification/notification';
|
} from '$lib/components/shared-components/notification/notification';
|
||||||
import { AppRoute, QueryParameter, maximumLengthSearchPeople, timeBeforeShowLoadingSpinner } from '$lib/constants';
|
import { AppRoute, QueryParameter } from '$lib/constants';
|
||||||
import { createAssetInteractionStore } from '$lib/stores/asset-interaction.store';
|
import { createAssetInteractionStore } from '$lib/stores/asset-interaction.store';
|
||||||
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
||||||
import { AssetStore } from '$lib/stores/assets.store';
|
import { AssetStore } from '$lib/stores/assets.store';
|
||||||
|
@ -35,7 +35,6 @@
|
||||||
import { clickOutside } from '$lib/utils/click-outside';
|
import { clickOutside } from '$lib/utils/click-outside';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import { isExternalUrl } from '$lib/utils/navigation';
|
import { isExternalUrl } from '$lib/utils/navigation';
|
||||||
import { searchNameLocal } from '$lib/utils/person';
|
|
||||||
import {
|
import {
|
||||||
getPersonStatistics,
|
getPersonStatistics,
|
||||||
mergePerson,
|
mergePerson,
|
||||||
|
@ -103,37 +102,12 @@
|
||||||
* However, it needs to make a new api request if searching 'r' returns 20 names (arbitrary value, the limit sent back by the server).
|
* However, it needs to make a new api request if searching 'r' returns 20 names (arbitrary value, the limit sent back by the server).
|
||||||
* or if the new search word starts with another word / letter
|
* or if the new search word starts with another word / letter
|
||||||
**/
|
**/
|
||||||
let searchWord: string;
|
|
||||||
let isSearchingPeople = false;
|
let isSearchingPeople = false;
|
||||||
let suggestionContainer: HTMLDivElement;
|
let suggestionContainer: HTMLDivElement;
|
||||||
|
|
||||||
const searchPeople = async () => {
|
|
||||||
if ((people.length < maximumLengthSearchPeople && name.startsWith(searchWord)) || name === '') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const timeout = setTimeout(() => (isSearchingPeople = true), timeBeforeShowLoadingSpinner);
|
|
||||||
try {
|
|
||||||
people = await searchPerson({ name });
|
|
||||||
searchWord = name;
|
|
||||||
} catch (error) {
|
|
||||||
people = [];
|
|
||||||
handleError(error, "Can't search people");
|
|
||||||
} finally {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
isSearchingPeople = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
$: isAllArchive = [...$selectedAssets].every((asset) => asset.isArchived);
|
$: isAllArchive = [...$selectedAssets].every((asset) => asset.isArchived);
|
||||||
$: isAllFavorite = [...$selectedAssets].every((asset) => asset.isFavorite);
|
$: isAllFavorite = [...$selectedAssets].every((asset) => asset.isFavorite);
|
||||||
|
|
||||||
$: {
|
|
||||||
if (people) {
|
|
||||||
suggestedPeople = name ? searchNameLocal(name, people, 5, data.person.id) : [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const action = $page.url.searchParams.get(QueryParameter.ACTION);
|
const action = $page.url.searchParams.get(QueryParameter.ACTION);
|
||||||
const getPreviousRoute = $page.url.searchParams.get(QueryParameter.PREVIOUS_ROUTE);
|
const getPreviousRoute = $page.url.searchParams.get(QueryParameter.PREVIOUS_ROUTE);
|
||||||
|
@ -480,10 +454,10 @@
|
||||||
{#if isEditingName}
|
{#if isEditingName}
|
||||||
<EditNameInput
|
<EditNameInput
|
||||||
person={data.person}
|
person={data.person}
|
||||||
suggestedPeople={suggestedPeople.length > 0 || isSearchingPeople}
|
bind:suggestedPeople
|
||||||
bind:name
|
bind:name
|
||||||
|
bind:isSearchingPeople
|
||||||
on:change={(event) => handleNameChange(event.detail)}
|
on:change={(event) => handleNameChange(event.detail)}
|
||||||
on:input={searchPeople}
|
|
||||||
{thumbnailData}
|
{thumbnailData}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
|
|
Loading…
Reference in a new issue