-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): add cover images to individual shares (#9988)
* feat(web): add cover images to individual shares * Update wording in share modal * Use translation function * Add and use new translations * Fix formatting * Update with suggestions * Update test language * Update test and language file per suggestions * Fix formatting * Remove unused translation
- Loading branch information
1 parent
78f600e
commit aea1c46
Showing
13 changed files
with
214 additions
and
30 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
web/src/lib/components/album-page/__tests__/album-cover.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import AlbumCover from '$lib/components/album-page/album-cover.svelte'; | ||
import { getAssetThumbnailUrl } from '$lib/utils'; | ||
import { albumFactory } from '@test-data'; | ||
import { render } from '@testing-library/svelte'; | ||
|
||
vi.mock('$lib/utils'); | ||
|
||
describe('AlbumCover component', () => { | ||
it('renders an image when the album has a thumbnail', () => { | ||
vi.mocked(getAssetThumbnailUrl).mockReturnValue('/asdf'); | ||
const component = render(AlbumCover, { | ||
album: albumFactory.build({ | ||
albumName: 'someName', | ||
albumThumbnailAssetId: '123', | ||
}), | ||
preload: false, | ||
class: 'text', | ||
}); | ||
const img = component.getByTestId('album-image') as HTMLImageElement; | ||
expect(img.alt).toBe('someName'); | ||
expect(img.getAttribute('loading')).toBe('lazy'); | ||
expect(img.className).toBe('z-0 rounded-xl object-cover text'); | ||
expect(img.getAttribute('src')).toBe('/asdf'); | ||
expect(getAssetThumbnailUrl).toHaveBeenCalledWith({ id: '123' }); | ||
}); | ||
|
||
it('renders an image when the album has no thumbnail', () => { | ||
const component = render(AlbumCover, { | ||
album: albumFactory.build({ | ||
albumName: '', | ||
albumThumbnailAssetId: null, | ||
}), | ||
preload: true, | ||
class: 'asdf', | ||
}); | ||
const img = component.getByTestId('album-image') as HTMLImageElement; | ||
expect(img.alt).toBe('unnamed_album'); | ||
expect(img.getAttribute('loading')).toBe('eager'); | ||
expect(img.className).toBe('z-0 rounded-xl object-cover asdf'); | ||
expect(img.getAttribute('src')).toStrictEqual(expect.any(String)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,23 @@ | ||
<script lang="ts"> | ||
import { getAssetThumbnailUrl } from '$lib/utils'; | ||
import { type AlbumResponseDto } from '@immich/sdk'; | ||
import NoCover from '$lib/components/sharedlinks-page/covers/no-cover.svelte'; | ||
import AssetCover from '$lib/components/sharedlinks-page/covers/asset-cover.svelte'; | ||
import { t } from 'svelte-i18n'; | ||
export let album: AlbumResponseDto | undefined; | ||
export let album: AlbumResponseDto; | ||
export let preload = false; | ||
export let css = ''; | ||
let className = ''; | ||
export { className as class }; | ||
$: thumbnailUrl = | ||
album && album.albumThumbnailAssetId ? getAssetThumbnailUrl({ id: album.albumThumbnailAssetId }) : null; | ||
$: alt = album.albumName || $t('unnamed_album'); | ||
$: thumbnailUrl = album.albumThumbnailAssetId ? getAssetThumbnailUrl({ id: album.albumThumbnailAssetId }) : null; | ||
</script> | ||
|
||
<div class="relative aspect-square"> | ||
{#if thumbnailUrl} | ||
<img | ||
loading={preload ? 'eager' : 'lazy'} | ||
src={thumbnailUrl} | ||
alt={album?.albumName ?? $t('unknown_album')} | ||
class="z-0 rounded-xl object-cover {css}" | ||
data-testid="album-image" | ||
draggable="false" | ||
/> | ||
<AssetCover {alt} class={className} src={thumbnailUrl} {preload} /> | ||
{:else} | ||
<enhanced:img | ||
loading={preload ? 'eager' : 'lazy'} | ||
src="$lib/assets/no-thumbnail.png" | ||
sizes="min(271px,186px)" | ||
alt={album?.albumName ?? $t('empty_album')} | ||
class="z-0 rounded-xl object-cover {css}" | ||
data-testid="album-image" | ||
draggable="false" | ||
/> | ||
<NoCover {alt} class={className} {preload} /> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
web/src/lib/components/sharedlinks-page/covers/__tests__/asset-cover.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import AssetCover from '$lib/components/sharedlinks-page/covers/asset-cover.svelte'; | ||
import { render } from '@testing-library/svelte'; | ||
|
||
describe('AssetCover component', () => { | ||
it('renders correctly', () => { | ||
const component = render(AssetCover, { | ||
alt: '123', | ||
preload: true, | ||
src: 'wee', | ||
class: 'asdf', | ||
}); | ||
const img = component.getByTestId('album-image') as HTMLImageElement; | ||
expect(img.alt).toBe('123'); | ||
expect(img.getAttribute('src')).toBe('wee'); | ||
expect(img.getAttribute('loading')).toBe('eager'); | ||
expect(img.className).toBe('z-0 rounded-xl object-cover asdf'); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
web/src/lib/components/sharedlinks-page/covers/__tests__/no-cover.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import NoCover from '$lib/components/sharedlinks-page/covers/no-cover.svelte'; | ||
import { render } from '@testing-library/svelte'; | ||
|
||
describe('NoCover component', () => { | ||
it('renders correctly', () => { | ||
const component = render(NoCover, { | ||
alt: '123', | ||
preload: true, | ||
class: 'asdf', | ||
}); | ||
const img = component.getByTestId('album-image') as HTMLImageElement; | ||
expect(img.alt).toBe('123'); | ||
expect(img.className).toBe('z-0 rounded-xl object-cover asdf'); | ||
expect(img.getAttribute('loading')).toBe('eager'); | ||
expect(img.src).toStrictEqual(expect.any(String)); | ||
}); | ||
}); |
60 changes: 60 additions & 0 deletions
60
web/src/lib/components/sharedlinks-page/covers/__tests__/share-cover.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import ShareCover from '$lib/components/sharedlinks-page/covers/share-cover.svelte'; | ||
import { getAssetThumbnailUrl } from '$lib/utils'; | ||
import type { SharedLinkResponseDto } from '@immich/sdk'; | ||
import { albumFactory } from '@test-data'; | ||
import { render } from '@testing-library/svelte'; | ||
|
||
vi.mock('$lib/utils'); | ||
|
||
describe('ShareCover component', () => { | ||
it('renders an image when the shared link is an album', () => { | ||
const component = render(ShareCover, { | ||
link: { | ||
album: albumFactory.build({ | ||
albumName: '123', | ||
}), | ||
} as SharedLinkResponseDto, | ||
preload: false, | ||
class: 'text', | ||
}); | ||
const img = component.getByTestId('album-image') as HTMLImageElement; | ||
expect(img.alt).toBe('123'); | ||
expect(img.getAttribute('loading')).toBe('lazy'); | ||
expect(img.className).toBe('z-0 rounded-xl object-cover text'); | ||
}); | ||
|
||
it('renders an image when the shared link is an individual share', () => { | ||
vi.mocked(getAssetThumbnailUrl).mockReturnValue('/asdf'); | ||
const component = render(ShareCover, { | ||
link: { | ||
assets: [ | ||
{ | ||
id: 'someId', | ||
}, | ||
], | ||
} as SharedLinkResponseDto, | ||
preload: false, | ||
class: 'text', | ||
}); | ||
const img = component.getByTestId('album-image') as HTMLImageElement; | ||
expect(img.alt).toBe('individual_share'); | ||
expect(img.getAttribute('loading')).toBe('lazy'); | ||
expect(img.className).toBe('z-0 rounded-xl object-cover text'); | ||
expect(img.getAttribute('src')).toBe('/asdf'); | ||
expect(getAssetThumbnailUrl).toHaveBeenCalledWith('someId'); | ||
}); | ||
|
||
it('renders an image when the shared link has no album or assets', () => { | ||
const component = render(ShareCover, { | ||
link: { | ||
assets: [], | ||
} as unknown as SharedLinkResponseDto, | ||
preload: false, | ||
class: 'text', | ||
}); | ||
const img = component.getByTestId('album-image') as HTMLImageElement; | ||
expect(img.alt).toBe('unnamed_share'); | ||
expect(img.getAttribute('loading')).toBe('lazy'); | ||
expect(img.className).toBe('z-0 rounded-xl object-cover text'); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
web/src/lib/components/sharedlinks-page/covers/asset-cover.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script lang="ts"> | ||
export let alt; | ||
export let preload = false; | ||
export let src: string; | ||
let className = ''; | ||
export { className as class }; | ||
</script> | ||
|
||
<img | ||
{alt} | ||
class="z-0 rounded-xl object-cover {className}" | ||
data-testid="album-image" | ||
draggable="false" | ||
loading={preload ? 'eager' : 'lazy'} | ||
{src} | ||
/> |
16 changes: 16 additions & 0 deletions
16
web/src/lib/components/sharedlinks-page/covers/no-cover.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script lang="ts"> | ||
export let alt = ''; | ||
export let preload = false; | ||
let className = ''; | ||
export { className as class }; | ||
</script> | ||
|
||
<enhanced:img | ||
{alt} | ||
class="z-0 rounded-xl object-cover {className}" | ||
data-testid="album-image" | ||
draggable="false" | ||
loading={preload ? 'eager' : 'lazy'} | ||
sizes="min(271px,186px)" | ||
src="$lib/assets/no-thumbnail.png" | ||
/> |
28 changes: 28 additions & 0 deletions
28
web/src/lib/components/sharedlinks-page/covers/share-cover.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<script lang="ts"> | ||
import type { SharedLinkResponseDto } from '@immich/sdk'; | ||
import AlbumCover from '$lib/components/album-page/album-cover.svelte'; | ||
import NoCover from '$lib/components/sharedlinks-page/covers/no-cover.svelte'; | ||
import AssetCover from '$lib/components/sharedlinks-page/covers/asset-cover.svelte'; | ||
import { getAssetThumbnailUrl } from '$lib/utils'; | ||
import { t } from 'svelte-i18n'; | ||
export let link: SharedLinkResponseDto; | ||
export let preload = false; | ||
let className = ''; | ||
export { className as class }; | ||
</script> | ||
|
||
<div class="relative aspect-square"> | ||
{#if link?.album} | ||
<AlbumCover album={link.album} class={className} {preload} /> | ||
{:else if link.assets[0]} | ||
<AssetCover | ||
alt={$t('individual_share')} | ||
class={className} | ||
{preload} | ||
src={getAssetThumbnailUrl(link.assets[0].id)} | ||
/> | ||
{:else} | ||
<NoCover alt={$t('unnamed_share')} class={className} {preload} /> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters