2024-12-04 21:38:55 +01:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import { getAssetThumbnailUrl } from '$lib/utils';
|
|
|
|
|
import { getAllAlbums, type AlbumResponseDto } from '@immich/sdk';
|
|
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
|
|
|
|
import { t } from 'svelte-i18n';
|
2024-12-16 15:45:01 +01:00
|
|
|
import { userInteraction } from '$lib/stores/user.svelte';
|
2024-12-04 21:38:55 +01:00
|
|
|
|
|
|
|
|
let albums: AlbumResponseDto[] = $state([]);
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
2024-12-16 15:45:01 +01:00
|
|
|
if (userInteraction.recentAlbums) {
|
|
|
|
|
albums = userInteraction.recentAlbums;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-12-04 21:38:55 +01:00
|
|
|
try {
|
|
|
|
|
const allAlbums = await getAllAlbums({});
|
2024-12-07 17:24:00 +01:00
|
|
|
albums = allAlbums.sort((a, b) => (a.updatedAt > b.updatedAt ? -1 : 1)).slice(0, 3);
|
2024-12-16 15:45:01 +01:00
|
|
|
userInteraction.recentAlbums = albums;
|
2024-12-04 21:38:55 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
handleError(error, $t('failed_to_load_assets'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
2025-03-03 14:24:26 +00:00
|
|
|
{#each albums as album (album.id)}
|
2024-12-04 21:38:55 +01:00
|
|
|
<a
|
|
|
|
|
href={'/albums/' + album.id}
|
|
|
|
|
title={album.albumName}
|
|
|
|
|
class="flex w-full place-items-center justify-between gap-4 rounded-r-full py-3 transition-[padding] delay-100 duration-100 hover:cursor-pointer hover:bg-immich-gray hover:text-immich-primary dark:text-immich-dark-fg dark:hover:bg-immich-dark-gray dark:hover:text-immich-dark-primary pl-10 group-hover:sm:px-10 md:px-10"
|
|
|
|
|
>
|
|
|
|
|
<div>
|
|
|
|
|
<div
|
|
|
|
|
class="h-6 w-6 bg-cover rounded bg-gray-200 dark:bg-gray-600"
|
|
|
|
|
style={album.albumThumbnailAssetId
|
|
|
|
|
? `background-image:url('${getAssetThumbnailUrl({ id: album.albumThumbnailAssetId })}')`
|
|
|
|
|
: ''}
|
|
|
|
|
></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="grow text-sm font-medium truncate">
|
|
|
|
|
{album.albumName}
|
|
|
|
|
</div>
|
|
|
|
|
</a>
|
|
|
|
|
{/each}
|