Files
immich/web/src/lib/components/sharedlinks-page/shared-link-card.svelte

109 lines
3.9 KiB
Svelte
Raw Normal View History

<script lang="ts">
2025-11-10 15:49:02 -05:00
import ActionButton from '$lib/components/ActionButton.svelte';
2024-07-01 00:34:52 +02:00
import ShareCover from '$lib/components/sharedlinks-page/covers/share-cover.svelte';
import { AppRoute } from '$lib/constants';
2025-11-10 15:49:02 -05:00
import { getSharedLinkActions } from '$lib/services/shared-link.service';
2024-07-01 00:34:52 +02:00
import { locale } from '$lib/stores/preferences.store';
import { SharedLinkType, type SharedLinkResponseDto } from '@immich/sdk';
import { Badge, ContextMenuButton, MenuItemType, Text } from '@immich/ui';
2024-07-01 00:34:52 +02:00
import { DateTime, type ToRelativeUnit } from 'luxon';
feat(web): translations (#9854) * First test * Added translation using Weblate (French) * Translated using Weblate (German) Currently translated at 100.0% (4 of 4 strings) Translation: immich/web Translate-URL: http://familie-mach.net/projects/immich/web/de/ * Translated using Weblate (French) Currently translated at 100.0% (4 of 4 strings) Translation: immich/web Translate-URL: http://familie-mach.net/projects/immich/web/fr/ * Further testing * Further testing * Translated using Weblate (German) Currently translated at 100.0% (18 of 18 strings) Translation: immich/web Translate-URL: http://familie-mach.net/projects/immich/web/de/ * Further work * Update string file. * More strings * Automatically changed strings * Add automatically translated german file for testing purposes * Fix merge-face-selector component * Make server stats strings uppercase * Fix uppercase string * Fix some strings in jobs-panel * Fix lower and uppercase strings. Add a few additional string. Fix a few unnecessary replacements * Update german test translations * Fix typo in locales file * Change string keys * Extract more strings * Extract and replace some more strings * Update testtranslationfile * Change translation keys * Fix rebase errors * Fix one more rebase error * Remove german translation file * Co-authored-by: Daniel Dietzler <danieldietzler@users.noreply.github.com> * chore: clean up translations * chore: add new line * fix formatting * chore: fixes * fix: loading and tests --------- Co-authored-by: root <root@Blacki> Co-authored-by: admin <admin@example.com> Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Daniel Dietzler <mail@ddietzler.dev>
2024-06-04 21:53:00 +02:00
import { t } from 'svelte-i18n';
interface Props {
2025-11-10 12:21:26 -05:00
sharedLink: SharedLinkResponseDto;
}
2025-11-10 15:49:02 -05:00
let { sharedLink }: Props = $props();
2024-07-01 00:34:52 +02:00
let now = DateTime.now();
2025-11-10 12:21:26 -05:00
let expiresAt = $derived(sharedLink.expiresAt ? DateTime.fromISO(sharedLink.expiresAt) : undefined);
let isExpired = $derived(expiresAt ? now > expiresAt : false);
2024-07-01 00:34:52 +02:00
const getCountDownExpirationDate = (expiresAtDate: DateTime, now: DateTime) => {
const relativeUnits: ToRelativeUnit[] = ['days', 'hours', 'minutes', 'seconds'];
const expirationCountdown = expiresAtDate.diff(now, relativeUnits).toObject();
2024-07-01 00:34:52 +02:00
for (const unit of relativeUnits) {
const value = expirationCountdown[unit];
if (value && value > 0) {
return expiresAtDate.toRelativeCalendar({ base: now, locale: $locale, unit });
}
}
};
2025-11-10 15:49:02 -05:00
const { Edit, Copy, Delete } = $derived(getSharedLinkActions($t, sharedLink));
</script>
<div
class="flex w-full border-b border-gray-200 transition-all hover:border-immich-primary dark:border-gray-600 dark:text-immich-gray dark:hover:border-immich-dark-primary"
>
<svelte:element
this={isExpired ? 'div' : 'a'}
2025-11-10 12:21:26 -05:00
href={isExpired ? undefined : `${AppRoute.SHARE}/${sharedLink.key}`}
class="flex gap-4 w-full py-4"
>
2025-11-10 12:21:26 -05:00
<ShareCover class="transition-all duration-300 hover:shadow-lg" {sharedLink} />
<div class="flex flex-col gap-2">
<Text size="large" color="primary" class="flex place-items-center gap-2 break-all">
{#if sharedLink.type === SharedLinkType.Album}
{sharedLink.album?.albumName}
{:else if sharedLink.type === SharedLinkType.Individual}
{$t('individual_share')}
{/if}
</Text>
<div class="flex flex-wrap gap-1">
{#if isExpired}
<Badge size="small" color="danger">{$t('expired')}</Badge>
{:else if expiresAt}
<Badge size="small" color="secondary">
{$t('expires_date', { values: { date: getCountDownExpirationDate(expiresAt, now) } })}
</Badge>
{:else}
<Badge size="small" color="secondary">{$t('expires_date', { values: { date: '∞' } })}</Badge>
{/if}
{#if sharedLink.slug}
<Badge size="small" color="secondary">{$t('custom_url')}</Badge>
{/if}
2025-11-10 12:21:26 -05:00
{#if sharedLink.allowUpload}
<Badge size="small" color="secondary">{$t('upload')}</Badge>
{/if}
{#if sharedLink.showMetadata && sharedLink.allowDownload}
<Badge size="small" color="secondary">{$t('download')}</Badge>
{/if}
2025-11-10 12:21:26 -05:00
{#if sharedLink.showMetadata}
<Badge size="small" color="secondary">{$t('exif')}</Badge>
{/if}
2025-11-10 12:21:26 -05:00
{#if sharedLink.password}
<Badge size="small" color="secondary">{$t('password')}</Badge>
{/if}
</div>
{#if sharedLink.description}
<Text size="small" class="line-clamp-1">{sharedLink.description}</Text>
{/if}
</div>
</svelte:element>
<div class="flex flex-auto flex-col place-content-center place-items-end text-end ms-4">
<div class="sm:flex hidden">
<ActionButton action={Edit} />
<ActionButton action={Copy} />
<ActionButton action={Delete} />
</div>
<div class="sm:hidden">
<ContextMenuButton
aria-label={$t('shared_link_options')}
position="top-right"
items={[Edit, Copy, MenuItemType.Divider, Delete]}
/>
</div>
</div>
</div>