Skip to content

fix(web): multiple fixes for people #9343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions web/src/lib/components/faces-page/merge-face-selector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
}>();

$: hasSelection = selectedPeople.length > 0;
$: unselectedPeople = people.filter(
(source) => !selectedPeople.some((selected) => selected.id === source.id) && source.id !== person.id,
);
$: peopleToNotShow = [...selectedPeople, person];

onMount(async () => {
const data = await getAllPeople({ withHidden: false });
Expand Down Expand Up @@ -150,13 +148,7 @@
</div>
</div>

<PeopleList
people={unselectedPeople}
peopleCopy={unselectedPeople}
unselectedPeople={selectedPeople}
{screenHeight}
on:select={({ detail }) => onSelect(detail)}
/>
<PeopleList {people} {peopleToNotShow} {screenHeight} on:select={({ detail }) => onSelect(detail)} />
</section>

{#if isShowConfirmation}
Expand Down
17 changes: 6 additions & 11 deletions web/src/lib/components/faces-page/people-list.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

export let screenHeight: number;
export let people: PersonResponseDto[];
export let peopleCopy: PersonResponseDto[];
export let unselectedPeople: PersonResponseDto[];
export let peopleToNotShow: PersonResponseDto[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this peopleToNotShow are filtered out people from the search query?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, on the unmerge and merge modals, there's people you don't to appear in the list, like the people already selected, the person to merge, to un-merge ...

let searchedPeopleLocal: PersonResponseDto[] = [];

let name = '';
let showPeople: PersonResponseDto[];
Expand All @@ -17,20 +17,15 @@
}>();

$: {
showPeople = people.filter(
(person) => !unselectedPeople.some((unselectedPerson) => unselectedPerson.id === person.id),
showPeople = name ? searchedPeopleLocal : people;
showPeople = showPeople.filter(
(person) => !peopleToNotShow.some((unselectedPerson) => unselectedPerson.id === person.id),
);
}
</script>

<div class=" w-40 sm:w-48 md:w-96 h-14 mb-8">
<SearchPeople
type="searchBar"
placeholder="Search people"
bind:searchName={name}
bind:searchedPeopleLocal={people}
onReset={() => (people = peopleCopy)}
/>
<SearchPeople type="searchBar" placeholder="Search people" bind:searchName={name} bind:searchedPeopleLocal />
</div>

<div
Expand Down
12 changes: 2 additions & 10 deletions web/src/lib/components/faces-page/unmerge-face-selector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
let hasSelection = false;
let screenHeight: number;

$: unselectedPeople = selectedPerson
? people.filter((person) => selectedPerson && person.id !== selectedPerson.id && personAssets.id !== person.id)
: people;
$: peopleToNotShow = selectedPerson ? [personAssets, selectedPerson] : [personAssets];

let dispatch = createEventDispatcher<{
confirm: void;
Expand Down Expand Up @@ -178,13 +176,7 @@
</div>
</div>
{/if}
<PeopleList
people={unselectedPeople}
peopleCopy={unselectedPeople}
unselectedPeople={selectedPerson ? [selectedPerson, personAssets] : [personAssets]}
{screenHeight}
on:select={({ detail }) => handleSelectedPerson(detail)}
/>
<PeopleList {people} {peopleToNotShow} {screenHeight} on:select={({ detail }) => handleSelectedPerson(detail)} />
</section>
</section>
</section>
15 changes: 12 additions & 3 deletions web/src/routes/(user)/people/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,23 @@
let edittingPerson: PersonResponseDto | null = null;
let searchedPeopleLocal: PersonResponseDto[] = [];
let handleSearchPeople: (force?: boolean, name?: string) => Promise<void>;
let showPeople: PersonResponseDto[] = [];
let countVisiblePeople: number;

let innerHeight: number;

for (const person of people) {
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 () => {
const getSearchedPeople = $page.url.searchParams.get(QueryParameter.SEARCHED_PEOPLE);
Expand Down Expand Up @@ -382,7 +391,7 @@

<UserPageLayout
title="People"
description={countVisiblePeople === 0 ? undefined : `(${countVisiblePeople.toLocaleString($locale)})`}
description={countVisiblePeople === 0 && !searchName ? undefined : `(${countVisiblePeople.toLocaleString($locale)})`}
>
<svelte:fragment slot="buttons">
{#if countTotalPeople > 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
import { AssetStore } from '$lib/stores/assets.store';
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 { handleError } from '$lib/utils/handle-error';
import { isExternalUrl } from '$lib/utils/navigation';
Expand Down Expand Up @@ -137,12 +137,23 @@
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 }) => {
// Prevent setting previousRoute to the current page.
if (from && from.route.id !== $page.route.id) {
previousRoute = from.url.href;
}
if (previousPersonId !== data.person.id) {
handlePromiseError(updateAssetCount());
assetStore = new AssetStore({
isArchived: false,
personId: data.person.id,
Expand Down Expand Up @@ -182,8 +193,7 @@
};

const handleMerge = async (person: PersonResponseDto) => {
const { assets } = await getPersonStatistics({ id: person.id });
numberOfAssets = assets;
await updateAssetCount();
await handleGoBack();

data.person = person;
Expand All @@ -204,15 +214,6 @@
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 [personToMerge, personToBeMergedIn] = response;
viewMode = ViewMode.VIEW_ASSETS;
Expand Down
Loading