1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 15:11:58 +00:00

fix(web): multiple fixes for people (#9343)

fix: multiple fixes for people

Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
martin 2024-05-09 23:23:49 +02:00 committed by GitHub
parent a8abf2753e
commit 757840c2fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 35 additions and 46 deletions

View file

@ -30,9 +30,7 @@
}>(); }>();
$: hasSelection = selectedPeople.length > 0; $: hasSelection = selectedPeople.length > 0;
$: unselectedPeople = people.filter( $: peopleToNotShow = [...selectedPeople, person];
(source) => !selectedPeople.some((selected) => selected.id === source.id) && source.id !== person.id,
);
onMount(async () => { onMount(async () => {
const data = await getAllPeople({ withHidden: false }); const data = await getAllPeople({ withHidden: false });
@ -150,13 +148,7 @@
</div> </div>
</div> </div>
<PeopleList <PeopleList {people} {peopleToNotShow} {screenHeight} on:select={({ detail }) => onSelect(detail)} />
people={unselectedPeople}
peopleCopy={unselectedPeople}
unselectedPeople={selectedPeople}
{screenHeight}
on:select={({ detail }) => onSelect(detail)}
/>
</section> </section>
{#if isShowConfirmation} {#if isShowConfirmation}

View file

@ -6,8 +6,8 @@
export let screenHeight: number; export let screenHeight: number;
export let people: PersonResponseDto[]; export let people: PersonResponseDto[];
export let peopleCopy: PersonResponseDto[]; export let peopleToNotShow: PersonResponseDto[];
export let unselectedPeople: PersonResponseDto[]; let searchedPeopleLocal: PersonResponseDto[] = [];
let name = ''; let name = '';
let showPeople: PersonResponseDto[]; let showPeople: PersonResponseDto[];
@ -17,20 +17,15 @@
}>(); }>();
$: { $: {
showPeople = people.filter( showPeople = name ? searchedPeopleLocal : people;
(person) => !unselectedPeople.some((unselectedPerson) => unselectedPerson.id === person.id), showPeople = showPeople.filter(
(person) => !peopleToNotShow.some((unselectedPerson) => unselectedPerson.id === person.id),
); );
} }
</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">
<SearchPeople <SearchPeople type="searchBar" placeholder="Search people" bind:searchName={name} bind:searchedPeopleLocal />
type="searchBar"
placeholder="Search people"
bind:searchName={name}
bind:searchedPeopleLocal={people}
onReset={() => (people = peopleCopy)}
/>
</div> </div>
<div <div

View file

@ -31,9 +31,7 @@
let hasSelection = false; let hasSelection = false;
let screenHeight: number; let screenHeight: number;
$: unselectedPeople = selectedPerson $: peopleToNotShow = selectedPerson ? [personAssets, selectedPerson] : [personAssets];
? people.filter((person) => selectedPerson && person.id !== selectedPerson.id && personAssets.id !== person.id)
: people;
let dispatch = createEventDispatcher<{ let dispatch = createEventDispatcher<{
confirm: void; confirm: void;
@ -178,13 +176,7 @@
</div> </div>
</div> </div>
{/if} {/if}
<PeopleList <PeopleList {people} {peopleToNotShow} {screenHeight} on:select={({ detail }) => handleSelectedPerson(detail)} />
people={unselectedPeople}
peopleCopy={unselectedPeople}
unselectedPeople={selectedPerson ? [selectedPerson, personAssets] : [personAssets]}
{screenHeight}
on:select={({ detail }) => handleSelectedPerson(detail)}
/>
</section> </section>
</section> </section>
</section> </section>

View file

@ -60,14 +60,23 @@
let edittingPerson: PersonResponseDto | null = null; let edittingPerson: PersonResponseDto | null = null;
let searchedPeopleLocal: PersonResponseDto[] = []; let searchedPeopleLocal: PersonResponseDto[] = [];
let handleSearchPeople: (force?: boolean, name?: string) => Promise<void>; let handleSearchPeople: (force?: boolean, name?: string) => Promise<void>;
let showPeople: PersonResponseDto[] = [];
let countVisiblePeople: number;
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); $: {
$: countVisiblePeople = countTotalPeople - countHiddenPeople; if (searchName) {
showPeople = searchedPeopleLocal;
countVisiblePeople = searchedPeopleLocal.length;
} else {
showPeople = people.filter((person) => !person.isHidden);
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);
@ -382,7 +391,7 @@
<UserPageLayout <UserPageLayout
title="People" title="People"
description={countVisiblePeople === 0 ? undefined : `(${countVisiblePeople.toLocaleString($locale)})`} description={countVisiblePeople === 0 && !searchName ? undefined : `(${countVisiblePeople.toLocaleString($locale)})`}
> >
<svelte:fragment slot="buttons"> <svelte:fragment slot="buttons">
{#if countTotalPeople > 0} {#if countTotalPeople > 0}

View file

@ -31,7 +31,7 @@
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';
import { websocketEvents } from '$lib/stores/websocket'; import { websocketEvents } from '$lib/stores/websocket';
import { getPeopleThumbnailUrl } from '$lib/utils'; import { getPeopleThumbnailUrl, handlePromiseError } from '$lib/utils';
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';
@ -137,12 +137,23 @@
return; return;
} }
}; };
const updateAssetCount = async () => {
try {
const { assets } = await getPersonStatistics({ id: data.person.id });
numberOfAssets = assets;
} catch (error) {
handleError(error, "Can't update the asset count");
}
};
afterNavigate(({ from }) => { afterNavigate(({ from }) => {
// Prevent setting previousRoute to the current page. // Prevent setting previousRoute to the current page.
if (from && from.route.id !== $page.route.id) { if (from && from.route.id !== $page.route.id) {
previousRoute = from.url.href; previousRoute = from.url.href;
} }
if (previousPersonId !== data.person.id) { if (previousPersonId !== data.person.id) {
handlePromiseError(updateAssetCount());
assetStore = new AssetStore({ assetStore = new AssetStore({
isArchived: false, isArchived: false,
personId: data.person.id, personId: data.person.id,
@ -182,8 +193,7 @@
}; };
const handleMerge = async (person: PersonResponseDto) => { const handleMerge = async (person: PersonResponseDto) => {
const { assets } = await getPersonStatistics({ id: person.id }); await updateAssetCount();
numberOfAssets = assets;
await handleGoBack(); await handleGoBack();
data.person = person; data.person = person;
@ -204,15 +214,6 @@
viewMode = ViewMode.VIEW_ASSETS; viewMode = ViewMode.VIEW_ASSETS;
}; };
const updateAssetCount = async () => {
try {
const { assets } = await getPersonStatistics({ id: data.person.id });
numberOfAssets = assets;
} catch (error) {
handleError(error, "Can't update the asset count");
}
};
const handleMergeSamePerson = async (response: [PersonResponseDto, PersonResponseDto]) => { const handleMergeSamePerson = async (response: [PersonResponseDto, PersonResponseDto]) => {
const [personToMerge, personToBeMergedIn] = response; const [personToMerge, personToBeMergedIn] = response;
viewMode = ViewMode.VIEW_ASSETS; viewMode = ViewMode.VIEW_ASSETS;