mirror of
https://github.com/immich-app/immich
synced 2026-08-29 13:15:45 +00:00
113 lines
3.7 KiB
TypeScript
113 lines
3.7 KiB
TypeScript
import { eventManager } from '$lib/managers/event-manager.svelte';
|
|
import PersonEditBirthDateModal from '$lib/modals/PersonEditBirthDateModal.svelte';
|
|
import { handleError } from '$lib/utils/handle-error';
|
|
import { getFormatter } from '$lib/utils/i18n';
|
|
import { updatePerson, type PersonResponseDto } from '@immich/sdk';
|
|
import { modalManager, toastManager, type ActionItem } from '@immich/ui';
|
|
import {
|
|
mdiCalendarEditOutline,
|
|
mdiEyeOffOutline,
|
|
mdiEyeOutline,
|
|
mdiHeartMinusOutline,
|
|
mdiHeartOutline,
|
|
} from '@mdi/js';
|
|
import type { MessageFormatter } from 'svelte-i18n';
|
|
|
|
export const getPersonActions = ($t: MessageFormatter, person: PersonResponseDto) => {
|
|
const SetDateOfBirth: ActionItem = {
|
|
title: $t('set_date_of_birth'),
|
|
icon: mdiCalendarEditOutline,
|
|
onAction: () => modalManager.show(PersonEditBirthDateModal, { person }),
|
|
};
|
|
|
|
const Favorite: ActionItem = {
|
|
title: $t('to_favorite'),
|
|
icon: mdiHeartOutline,
|
|
$if: () => !person.isFavorite,
|
|
onAction: () => handleFavoritePerson(person),
|
|
};
|
|
|
|
const Unfavorite: ActionItem = {
|
|
title: $t('unfavorite'),
|
|
icon: mdiHeartMinusOutline,
|
|
$if: () => !!person.isFavorite,
|
|
onAction: () => handleUnfavoritePerson(person),
|
|
};
|
|
|
|
const HidePerson: ActionItem = {
|
|
title: $t('hide_person'),
|
|
icon: mdiEyeOffOutline,
|
|
$if: () => !person.isHidden,
|
|
onAction: () => handleHidePerson(person),
|
|
};
|
|
|
|
const ShowPerson: ActionItem = {
|
|
title: $t('unhide_person'),
|
|
icon: mdiEyeOutline,
|
|
$if: () => !!person.isHidden,
|
|
onAction: () => handleShowPerson(person),
|
|
};
|
|
|
|
return { SetDateOfBirth, Favorite, Unfavorite, HidePerson, ShowPerson };
|
|
};
|
|
|
|
const handleFavoritePerson = async (person: { id: string }) => {
|
|
const $t = await getFormatter();
|
|
|
|
try {
|
|
const response = await updatePerson({ id: person.id, personUpdateDto: { isFavorite: true } });
|
|
eventManager.emit('PersonUpdate', response);
|
|
toastManager.success($t('added_to_favorites'));
|
|
} catch (error) {
|
|
handleError(error, $t('errors.unable_to_add_remove_favorites', { values: { favorite: false } }));
|
|
}
|
|
};
|
|
|
|
const handleUnfavoritePerson = async (person: { id: string }) => {
|
|
const $t = await getFormatter();
|
|
|
|
try {
|
|
const response = await updatePerson({ id: person.id, personUpdateDto: { isFavorite: false } });
|
|
eventManager.emit('PersonUpdate', response);
|
|
toastManager.success($t('removed_from_favorites'));
|
|
} catch (error) {
|
|
handleError(error, $t('errors.unable_to_add_remove_favorites', { values: { favorite: false } }));
|
|
}
|
|
};
|
|
|
|
const handleHidePerson = async (person: { id: string }) => {
|
|
const $t = await getFormatter();
|
|
|
|
try {
|
|
const response = await updatePerson({ id: person.id, personUpdateDto: { isHidden: true } });
|
|
toastManager.success($t('changed_visibility_successfully'));
|
|
eventManager.emit('PersonUpdate', response);
|
|
} catch (error) {
|
|
handleError(error, $t('errors.unable_to_hide_person'));
|
|
}
|
|
};
|
|
|
|
const handleShowPerson = async (person: { id: string }) => {
|
|
const $t = await getFormatter();
|
|
|
|
try {
|
|
const response = await updatePerson({ id: person.id, personUpdateDto: { isHidden: false } });
|
|
toastManager.success($t('changed_visibility_successfully'));
|
|
eventManager.emit('PersonUpdate', response);
|
|
} catch (error) {
|
|
handleError(error, $t('errors.something_went_wrong'));
|
|
}
|
|
};
|
|
|
|
export const handleUpdatePersonBirthDate = async (person: PersonResponseDto, birthDate: string) => {
|
|
const $t = await getFormatter();
|
|
|
|
try {
|
|
const response = await updatePerson({ id: person.id, personUpdateDto: { birthDate } });
|
|
toastManager.success($t('date_of_birth_saved'));
|
|
eventManager.emit('PersonUpdate', response);
|
|
return true;
|
|
} catch (error) {
|
|
handleError(error, $t('errors.unable_to_save_date_of_birth'));
|
|
}
|
|
};
|