Skip to content

High performance self-hosted photo and video management solution.

1.1 KB
Raw Blame
<script lang="ts">
  import MenuOption from '#lib/components/shared-components/context-menu/MenuOption.svelte';
  import { AssetAction } from '#lib/constants.ts';
  import { handleError } from '#lib/utils/handle-error.ts';
  import { toTimelineAsset } from '#lib/utils/timeline-util.ts';
  import { restoreAssets, type AssetResponseDto } from '@immich/sdk';
  import { toastManager } from '@immich/ui';
  import { mdiHistory } from '@mdi/js';
  import { t } from 'svelte-i18n';
  import type { OnAction } from './action';

  interface Props {
    asset: AssetResponseDto;
    onAction: OnAction;
  }

  let { asset = $bindable(), onAction }: Props = $props();

  const handleRestoreAsset = async () => {
    try {
      await restoreAssets({ bulkIdsDto: { ids: [asset.id] } });
      asset.isTrashed = false;
      onAction({ type: AssetAction.RESTORE, asset: toTimelineAsset(asset) });
      toastManager.primary($t('restored_asset'));
    } catch (error) {
      handleError(error, $t('errors.unable_to_restore_assets'));
    }
  };
</script>

<MenuOption icon={mdiHistory} onClick={handleRestoreAsset} text={$t('restore')} />