mirror of
https://github.com/immich-app/immich.git
synced 2026-02-21 04:00:40 +09:00
simple
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<script lang="ts">
|
||||
import MenuOption from '$lib/components/shared-components/context-menu/menu-option.svelte';
|
||||
import { AssetAction } from '$lib/constants';
|
||||
import { getAssetControlContext } from '$lib/utils/context';
|
||||
import { handleError } from '$lib/utils/handle-error';
|
||||
import { updatePerson, type AssetResponseDto, type PersonResponseDto } from '@immich/sdk';
|
||||
import { toastManager } from '@immich/ui';
|
||||
@@ -10,50 +9,27 @@
|
||||
import type { OnAction } from './action';
|
||||
|
||||
interface Props {
|
||||
asset?: AssetResponseDto;
|
||||
asset: AssetResponseDto;
|
||||
person: PersonResponseDto;
|
||||
onAction?: OnAction;
|
||||
menuItem?: boolean;
|
||||
onPersonUpdate?: (person: PersonResponseDto) => void;
|
||||
}
|
||||
|
||||
let { asset, person = $bindable(), onAction, menuItem = false, onPersonUpdate }: Props = $props();
|
||||
let { asset, person, onAction }: Props = $props();
|
||||
|
||||
const handleSelectFeaturePhoto = async () => {
|
||||
let assetId: string;
|
||||
|
||||
if (menuItem) {
|
||||
const { getAssets, clearSelect } = getAssetControlContext();
|
||||
const assets = getAssets();
|
||||
if (assets.length !== 1) {
|
||||
return;
|
||||
}
|
||||
assetId = assets[0].id;
|
||||
clearSelect();
|
||||
} else {
|
||||
if (!asset) {
|
||||
return;
|
||||
}
|
||||
assetId = asset.id;
|
||||
}
|
||||
|
||||
try {
|
||||
const updatedPerson = await updatePerson({
|
||||
id: person.id,
|
||||
personUpdateDto: { featureFaceAssetId: assetId },
|
||||
personUpdateDto: { featureFaceAssetId: asset.id },
|
||||
});
|
||||
|
||||
const mergedPerson = { ...person, ...updatedPerson };
|
||||
person = mergedPerson;
|
||||
onPersonUpdate?.(mergedPerson);
|
||||
person = { ...person, ...updatedPerson };
|
||||
|
||||
if (!menuItem && asset) {
|
||||
onAction?.({
|
||||
type: AssetAction.SET_PERSON_FEATURED_PHOTO,
|
||||
asset,
|
||||
person: mergedPerson,
|
||||
});
|
||||
}
|
||||
onAction?.({
|
||||
type: AssetAction.SET_PERSON_FEATURED_PHOTO,
|
||||
asset,
|
||||
person,
|
||||
});
|
||||
|
||||
toastManager.success($t('feature_photo_updated'));
|
||||
} catch (error) {
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
import SetVisibilityAction from '$lib/components/timeline/actions/SetVisibilityAction.svelte';
|
||||
import TagAction from '$lib/components/timeline/actions/TagAction.svelte';
|
||||
import AssetSelectControlBar from '$lib/components/timeline/AssetSelectControlBar.svelte';
|
||||
import SetFeaturedPhotoAction from '$lib/components/asset-viewer/actions/set-person-featured-action.svelte';
|
||||
import Timeline from '$lib/components/timeline/Timeline.svelte';
|
||||
import { PersonPageViewMode, QueryParameter, SessionStorageKey } from '$lib/constants';
|
||||
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
|
||||
@@ -42,7 +41,13 @@
|
||||
import { isExternalUrl } from '$lib/utils/navigation';
|
||||
import { AssetVisibility, searchPerson, updatePerson, type PersonResponseDto } from '@immich/sdk';
|
||||
import { ContextMenuButton, LoadingSpinner, modalManager, toastManager, type ActionItem } from '@immich/ui';
|
||||
import { mdiAccountBoxOutline, mdiAccountMultipleCheckOutline, mdiArrowLeft, mdiDotsVertical } from '@mdi/js';
|
||||
import {
|
||||
mdiAccountBoxOutline,
|
||||
mdiAccountMultipleCheckOutline,
|
||||
mdiArrowLeft,
|
||||
mdiDotsVertical,
|
||||
mdiFaceManProfile,
|
||||
} from '@mdi/js';
|
||||
import { DateTime } from 'luxon';
|
||||
import { onMount } from 'svelte';
|
||||
import { t } from 'svelte-i18n';
|
||||
@@ -152,6 +157,19 @@
|
||||
viewMode = PersonPageViewMode.VIEW_ASSETS;
|
||||
};
|
||||
|
||||
const updateFeaturedPhotoUsingCurrentSelection = async () => {
|
||||
if (assetInteraction.selectedAssets.length === 1) {
|
||||
const [firstAsset] = assetInteraction.selectedAssets;
|
||||
try {
|
||||
person = await updatePerson({ id: person.id, personUpdateDto: { featureFaceAssetId: firstAsset.id } });
|
||||
toastManager.success($t('feature_photo_updated'));
|
||||
assetInteraction.clearMultiselect();
|
||||
} catch (error) {
|
||||
handleError(error, $t('errors.unable_to_set_feature_photo'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleMergeSuggestion = async (): Promise<{ merged: boolean }> => {
|
||||
if (!personMerge1 || !personMerge2) {
|
||||
return { merged: false };
|
||||
@@ -474,12 +492,10 @@
|
||||
<ChangeDescription menuItem />
|
||||
<ChangeLocation menuItem />
|
||||
{#if assetInteraction.selectedAssets.length === 1}
|
||||
<SetFeaturedPhotoAction
|
||||
{person}
|
||||
menuItem
|
||||
onPersonUpdate={(updatedPerson) => {
|
||||
data = { ...data, person: updatedPerson };
|
||||
}}
|
||||
<MenuOption
|
||||
text={$t('set_as_featured_photo')}
|
||||
icon={mdiFaceManProfile}
|
||||
onClick={() => updateFeaturedPhotoUsingCurrentSelection()}
|
||||
/>
|
||||
{/if}
|
||||
<ArchiveAction
|
||||
|
||||
Reference in New Issue
Block a user