High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
<script lang="ts">
import { lang, locale } from '#lib/stores/preferences.store.ts';
import { getAssetMediaUrl } from '#lib/utils.ts';
import { getAllMetadataItems, type DifferingMetadataFields } from '#lib/utils/duplicate-utils.ts';
import { getAltText } from '#lib/utils/thumbnail-util.ts';
import { toTimelineAsset } from '#lib/utils/timeline-util.ts';
import { getAlbumsByAssetQuery } from '#lib/queries/album.query.ts';
import { type AssetResponseDto } from '@immich/sdk';
import { Icon } from '@immich/ui';
import { mdiBookmarkOutline, mdiHeart, mdiImageMultipleOutline, mdiMagnifyPlus } from '@mdi/js';
import { createQuery } from '@tanstack/svelte-query';
import { t } from 'svelte-i18n';
import InfoRow from './InfoRow.svelte';
interface Props {
asset: AssetResponseDto;
isSelected: boolean;
onSelectAsset: (asset: AssetResponseDto) => void;
onViewAsset: (asset: AssetResponseDto) => void;
differingMetadataFields: DifferingMetadataFields;
showMore?: boolean;
initialVisibleCount?: number;
}
let {
asset,
isSelected,
onSelectAsset,
onViewAsset,
differingMetadataFields,
showMore = false,
initialVisibleCount = 5,
}: Props = $props();
const query = createQuery(() => getAlbumsByAssetQuery(asset.id));
const albums = $derived(query.data);
const listFormat = $derived(new Intl.ListFormat($lang));
const isFromExternalLibrary = $derived(!!asset.libraryId);
const visibleMetadataItems = $derived(
getAllMetadataItems(asset, $t, $locale)
.filter(({ keys }) => keys.some((k) => differingMetadataFields[k]))
.slice(0, showMore ? undefined : initialVisibleCount),
);
</script>
<div class="min-w-60 flex-1 overflow-hidden rounded-lg border transition-colors">
<div class="relative w-full">
<button
type="button"
onclick={() => onSelectAsset(asset)}
class="relative block w-full"
aria-pressed={isSelected}
aria-label={$t('keep')}
>
<!-- THUMBNAIL-->
<img
src={getAssetMediaUrl({ id: asset.id })}
alt={$getAltText(toTimelineAsset(asset))}
class="h-60 w-full object-cover"
draggable="false"
/>
<!-- FAVORITE ICON -->
{#if asset.isFavorite}
<div class="absolute inset-s-2 bottom-2">
<Icon icon={mdiHeart} size="24" class="text-white" />
</div>
{/if}
<!-- OVERLAY CHIP -->
<div
class="absolute inset-e-3 bottom-1 rounded-xl px-4 py-1 text-xs transition-colors {isSelected
? 'bg-green-400/90'
: 'bg-red-300/90'} text-black"
>
{isSelected ? $t('keep') : $t('to_trash')}
</div>
<!-- EXTERNAL LIBRARY / STACK COUNT CHIP -->
<div class="absolute inset-e-3 top-2">
{#if isFromExternalLibrary}
<div class="rounded-xl bg-immich-primary/90 px-2 py-1 text-xs text-white">
{$t('external')}
</div>
{/if}
{#if asset.stack?.assetCount}
<div class="my-0.5 rounded-xl bg-immich-primary/90 px-2 py-1 text-xs text-white">
<div class="flex items-center justify-center">
<div class="me-1">{asset.stack.assetCount}</div>
<Icon icon={mdiImageMultipleOutline} size="18" />
</div>
</div>
{/if}
</div>
</button>
<button
type="button"
onclick={() => onViewAsset(asset)}
class="absolute inset-s-1 top-1 rounded-full bg-black/35 p-2 text-gray-200 hover:bg-black/50 hover:text-white"
title={$t('view')}
>
<Icon aria-label={$t('view')} icon={mdiMagnifyPlus} flipped size="18" />
</button>
</div>
<div
class="grid place-items-start divide-y text-sm transition-colors {isSelected
? 'bg-success/15 dark:bg-[#001a06]'
: 'bg-transparent'}"
>
{#each visibleMetadataItems as { icon, title, render, tooltip, keys } (keys[0])}
<InfoRow {icon} {title} {tooltip}>
{render}
</InfoRow>
{/each}
<!-- Albums always shown -->
<InfoRow icon={mdiBookmarkOutline} title={$t('albums')}>
{#if !albums}
{$t('scanning_for_album')}
{:else if albums.length === 1}
{albums[0].albumName}
{:else}
<span title={listFormat.format(albums.map(({ albumName }) => albumName))}>
{$t('in_albums', { values: { count: albums.length } })}
</span>
{/if}
</InfoRow>
</div>
</div>