diff --git a/web/src/routes/(user)/people/[personId]/[[photos=photos]]/[[assetId=id]]/+page.svelte b/web/src/routes/(user)/people/[personId]/[[photos=photos]]/[[assetId=id]]/+page.svelte index 26e803deb6fd4..daa5821e8506b 100644 --- a/web/src/routes/(user)/people/[personId]/[[photos=photos]]/[[assetId=id]]/+page.svelte +++ b/web/src/routes/(user)/people/[personId]/[[photos=photos]]/[[assetId=id]]/+page.svelte @@ -76,13 +76,20 @@ isArchived: false, personId: data.person.id, }); + + $: person = data.person; + $: thumbnailData = getPeopleThumbnailUrl(person); + $: if (person) { + handlePromiseError(updateAssetCount()); + handlePromiseError(assetStore.updateOptions({ personId: person.id })); + } + const assetInteractionStore = createAssetInteractionStore(); const { selectedAssets, isMultiSelectState } = assetInteractionStore; let viewMode: ViewMode = ViewMode.VIEW_ASSETS; let isEditingName = false; let previousRoute: string = AppRoute.EXPLORE; - let previousPersonId: string = data.person.id; let people: PersonResponseDto[] = []; let personMerge1: PersonResponseDto; let personMerge2: PersonResponseDto; @@ -91,9 +98,6 @@ let refreshAssetGrid = false; let personName = ''; - $: thumbnailData = getPeopleThumbnailUrl(data.person); - - let name: string = data.person.name; let suggestedPeople: PersonResponseDto[] = []; /** @@ -120,8 +124,8 @@ } return websocketEvents.on('on_person_thumbnail', (personId: string) => { - if (data.person.id === personId) { - thumbnailData = getPeopleThumbnailUrl(data.person, Date.now().toString()); + if (person.id === personId) { + thumbnailData = getPeopleThumbnailUrl(person, Date.now().toString()); } }); }); @@ -141,7 +145,7 @@ const updateAssetCount = async () => { try { - const { assets } = await getPersonStatistics({ id: data.person.id }); + const { assets } = await getPersonStatistics({ id: person.id }); numberOfAssets = assets; } catch (error) { handleError(error, "Can't update the asset count"); @@ -150,20 +154,9 @@ afterNavigate(({ from }) => { // Prevent setting previousRoute to the current page. - if (from && from.route.id !== $page.route.id) { + if (from?.url && from.route.id !== $page.route.id) { previousRoute = from.url.href; } - if (previousPersonId !== data.person.id) { - handlePromiseError(updateAssetCount()); - assetStore.destroy(); - assetStore = new AssetStore({ - isArchived: false, - personId: data.person.id, - }); - previousPersonId = data.person.id; - name = data.person.name; - refreshAssetGrid = !refreshAssetGrid; - } }); const handleUnmerge = () => { @@ -179,8 +172,8 @@ const toggleHidePerson = async () => { try { await updatePerson({ - id: data.person.id, - personUpdateDto: { isHidden: !data.person.isHidden }, + id: person.id, + personUpdateDto: { isHidden: !person.isHidden }, }); notificationController.show({ @@ -208,7 +201,7 @@ return; } try { - await updatePerson({ id: data.person.id, personUpdateDto: { featureFaceAssetId: asset.id } }); + await updatePerson({ id: person.id, personUpdateDto: { featureFaceAssetId: asset.id } }); notificationController.show({ message: $t('feature_photo_updated'), type: NotificationType.Info }); } catch (error) { handleError(error, $t('errors.unable_to_set_feature_photo')); @@ -233,7 +226,7 @@ type: NotificationType.Info, }); people = people.filter((person: PersonResponseDto) => person.id !== personToMerge.id); - if (personToBeMergedIn.name != personName && data.person.id === personToBeMergedIn.id) { + if (personToBeMergedIn.name != personName && person.id === personToBeMergedIn.id) { await updateAssetCount(); refreshAssetGrid = !refreshAssetGrid; return; @@ -244,22 +237,22 @@ } }; - const handleSuggestPeople = (person: PersonResponseDto) => { + const handleSuggestPeople = (person2: PersonResponseDto) => { isEditingName = false; potentialMergePeople = []; personName = person.name; - personMerge1 = data.person; - personMerge2 = person; + personMerge1 = person; + personMerge2 = person2; viewMode = ViewMode.SUGGEST_MERGE; }; const changeName = async () => { viewMode = ViewMode.VIEW_ASSETS; - data.person.name = personName; + person.name = personName; try { isEditingName = false; - await updatePerson({ id: data.person.id, personUpdateDto: { name: personName } }); + await updatePerson({ id: person.id, personUpdateDto: { name: personName } }); notificationController.show({ message: $t('change_name_successfully'), @@ -283,7 +276,7 @@ potentialMergePeople = []; personName = name; - if (data.person.name === personName) { + if (person.name === personName) { return; } if (name === '') { @@ -294,12 +287,11 @@ const result = await searchPerson({ name: personName, withHidden: true }); const existingPerson = result.find( - (person: PersonResponseDto) => - person.name.toLowerCase() === personName.toLowerCase() && person.id !== data.person.id && person.name, + ({ name, id }: PersonResponseDto) => name.toLowerCase() === personName.toLowerCase() && id !== person.id && name, ); if (existingPerson) { personMerge2 = existingPerson; - personMerge1 = data.person; + personMerge1 = person; potentialMergePeople = result .filter( (person: PersonResponseDto) => @@ -318,10 +310,10 @@ const handleSetBirthDate = async (birthDate: string) => { try { viewMode = ViewMode.VIEW_ASSETS; - data.person.birthDate = birthDate; + person.birthDate = birthDate; const updatedPerson = await updatePerson({ - id: data.person.id, + id: person.id, personUpdateDto: { birthDate: birthDate.length > 0 ? birthDate : null }, }); @@ -354,7 +346,7 @@ {#if viewMode === ViewMode.UNASSIGN_ASSETS} a.id)} - personAssets={data.person} + personAssets={person} on:close={() => (viewMode = ViewMode.VIEW_ASSETS)} on:confirm={handleUnmerge} /> @@ -373,14 +365,14 @@ {#if viewMode === ViewMode.BIRTH_DATE} (viewMode = ViewMode.VIEW_ASSETS)} on:updated={(event) => handleSetBirthDate(event.detail)} /> {/if} {#if viewMode === ViewMode.MERGE_PEOPLE} - handleMerge(detail)} /> + handleMerge(detail)} /> {/if}
@@ -394,7 +386,7 @@ assetStore.triggerUpdate()} /> - + (viewMode = ViewMode.SELECT_PERSON)} /> toggleHidePerson()} />
- {#key refreshAssetGrid} + {#key person.id} {#if isEditingName} handleNameChange(event.detail)} {thumbnailData} @@ -487,15 +479,15 @@ circle shadow url={thumbnailData} - altText={data.person.name} + altText={person.name} widthStyle="3.375rem" heightStyle="3.375rem" />
- {#if data.person.name} -

{data.person.name}

+ {#if person.name} +

{person.name}

{$t('assets_count', { values: { count: numberOfAssets } })}