diff --git a/projects/client/i18n/meta/en.json b/projects/client/i18n/meta/en.json index 063dc92e76..c6b4f83642 100644 --- a/projects/client/i18n/meta/en.json +++ b/projects/client/i18n/meta/en.json @@ -11144,6 +11144,14 @@ "default": "Tilt your phone to move the poster", "description": "Aria-label and tooltip for the small button on a living poster that asks for access to the phone's motion sensors, so the poster can follow how the phone is tilted. Shown on touch devices that need the person's permission first." }, + "text_living_poster_unavailable": { + "default": "This title has no living poster yet.", + "description": "Short line shown over the still poster on the full-screen living poster page when the title has no living poster, or the person cannot see living posters." + }, + "text_living_poster_reduced_motion": { + "default": "Living posters stay still when reduced motion is on.", + "description": "Short line shown over the still poster on the full-screen living poster page when the device asks for reduced motion, so the poster is not animated." + }, "button_label_edit_mode": { "default": "Edit mode", "description": "Aria-label for the button that allows users to enter edit mode to customize their dashboard." diff --git a/projects/client/src/lib/features/living-poster/_internal/isLivingPosterAvailable.spec.ts b/projects/client/src/lib/features/living-poster/_internal/isLivingPosterAvailable.spec.ts new file mode 100644 index 0000000000..d9251a60e2 --- /dev/null +++ b/projects/client/src/lib/features/living-poster/_internal/isLivingPosterAvailable.spec.ts @@ -0,0 +1,46 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { fetchLivingPoster } from './fetchLivingPoster.ts'; +import { fetchLivingPosterIndex } from './fetchLivingPosterIndex.ts'; +import { isLivingPosterAvailable } from './isLivingPosterAvailable.ts'; + +vi.mock('./fetchLivingPosterIndex.ts', () => ({ + fetchLivingPosterIndex: vi.fn(), +})); +vi.mock('./fetchLivingPoster.ts', () => ({ fetchLivingPoster: vi.fn() })); + +const target = { type: 'movie', id: 10 } as const; +const index = { movies: new Set([10]), shows: new Set([20]) }; + +describe('util: isLivingPosterAvailable', () => { + beforeEach(() => { + vi.resetAllMocks(); + }); + + it('should be true when the index lists the title and its poster loads', async () => { + vi.mocked(fetchLivingPosterIndex).mockResolvedValue(index); + vi.mocked(fetchLivingPoster).mockResolvedValue({} as never); + + expect(await isLivingPosterAvailable(target)).toBe(true); + }); + + it('should be false when the index is unavailable', async () => { + vi.mocked(fetchLivingPosterIndex).mockResolvedValue(null); + + expect(await isLivingPosterAvailable(target)).toBe(false); + expect(fetchLivingPoster).not.toHaveBeenCalled(); + }); + + it('should be false when the index does not list the title', async () => { + vi.mocked(fetchLivingPosterIndex).mockResolvedValue(index); + + expect(await isLivingPosterAvailable({ type: 'show', id: 10 })).toBe(false); + expect(fetchLivingPoster).not.toHaveBeenCalled(); + }); + + it('should be false when the poster file fails to load', async () => { + vi.mocked(fetchLivingPosterIndex).mockResolvedValue(index); + vi.mocked(fetchLivingPoster).mockResolvedValue(null); + + expect(await isLivingPosterAvailable(target)).toBe(false); + }); +}); diff --git a/projects/client/src/lib/features/living-poster/_internal/isLivingPosterAvailable.ts b/projects/client/src/lib/features/living-poster/_internal/isLivingPosterAvailable.ts new file mode 100644 index 0000000000..006ed9e506 --- /dev/null +++ b/projects/client/src/lib/features/living-poster/_internal/isLivingPosterAvailable.ts @@ -0,0 +1,11 @@ +import type { LivingPosterTarget } from '../models/LivingPosterTarget.ts'; +import { fetchLivingPoster } from './fetchLivingPoster.ts'; +import { fetchLivingPosterIndex } from './fetchLivingPosterIndex.ts'; +import { hasLivingPoster } from './hasLivingPoster.ts'; + +export async function isLivingPosterAvailable(target: LivingPosterTarget) { + const index = await fetchLivingPosterIndex(); + if (!index || !hasLivingPoster({ index, target })) return false; + + return (await fetchLivingPoster(target)) !== null; +} diff --git a/projects/client/src/lib/features/living-poster/_internal/toFullScreenPosterView.spec.ts b/projects/client/src/lib/features/living-poster/_internal/toFullScreenPosterView.spec.ts new file mode 100644 index 0000000000..f8c4474c75 --- /dev/null +++ b/projects/client/src/lib/features/living-poster/_internal/toFullScreenPosterView.spec.ts @@ -0,0 +1,25 @@ +import { describe, expect, it } from 'vitest'; +import { toFullScreenPosterView } from './toFullScreenPosterView.ts'; + +describe('util: toFullScreenPosterView', () => { + it('should go live when the poster exists and motion is allowed', () => { + expect( + toFullScreenPosterView({ isAvailable: true, isReducedMotion: false }), + ).toBe('live'); + }); + + it('should hold the static poster when motion is reduced', () => { + expect( + toFullScreenPosterView({ isAvailable: true, isReducedMotion: true }), + ).toBe('reduced-motion'); + }); + + it('should report a missing poster whatever the motion setting', () => { + expect( + toFullScreenPosterView({ isAvailable: false, isReducedMotion: false }), + ).toBe('unavailable'); + expect( + toFullScreenPosterView({ isAvailable: false, isReducedMotion: true }), + ).toBe('unavailable'); + }); +}); diff --git a/projects/client/src/lib/features/living-poster/_internal/toFullScreenPosterView.ts b/projects/client/src/lib/features/living-poster/_internal/toFullScreenPosterView.ts new file mode 100644 index 0000000000..791a51e37b --- /dev/null +++ b/projects/client/src/lib/features/living-poster/_internal/toFullScreenPosterView.ts @@ -0,0 +1,14 @@ +type FullScreenPosterViewParams = { + isAvailable: boolean; + isReducedMotion: boolean; +}; + +export function toFullScreenPosterView({ + isAvailable, + isReducedMotion, +}: FullScreenPosterViewParams) { + if (!isAvailable) return 'unavailable'; + if (isReducedMotion) return 'reduced-motion'; + + return 'live'; +} diff --git a/projects/client/src/lib/features/living-poster/components/FullScreenLivingPoster.svelte b/projects/client/src/lib/features/living-poster/components/FullScreenLivingPoster.svelte new file mode 100644 index 0000000000..94c2e5eaec --- /dev/null +++ b/projects/client/src/lib/features/living-poster/components/FullScreenLivingPoster.svelte @@ -0,0 +1,110 @@ + + +
+
+ {#if poster} + + {/if} +
+ + + {#snippet enabled()} + {#if target && view} + {#await view then resolved} + {#if resolved === "live"} + (isSettled = settled)} + /> + {:else if resolved === "reduced-motion"} +

+ {m.text_living_poster_reduced_motion()} +

+ {:else} +

+ {m.text_living_poster_unavailable()} +

+ {/if} + {/await} + {/if} + {/snippet} + +

+ {m.text_living_poster_unavailable()} +

+
+
+ + diff --git a/projects/client/src/lib/sections/living-poster/LivingPosterPage.svelte b/projects/client/src/lib/sections/living-poster/LivingPosterPage.svelte new file mode 100644 index 0000000000..88cb31edf9 --- /dev/null +++ b/projects/client/src/lib/sections/living-poster/LivingPosterPage.svelte @@ -0,0 +1,98 @@ + + + + + + + + + diff --git a/projects/client/src/routes/movies/[slug]/living-poster/+page.svelte b/projects/client/src/routes/movies/[slug]/living-poster/+page.svelte new file mode 100644 index 0000000000..45b2e8e2ca --- /dev/null +++ b/projects/client/src/routes/movies/[slug]/living-poster/+page.svelte @@ -0,0 +1,18 @@ + + + diff --git a/projects/client/src/routes/shows/[slug]/living-poster/+page.svelte b/projects/client/src/routes/shows/[slug]/living-poster/+page.svelte new file mode 100644 index 0000000000..b58c1fe12e --- /dev/null +++ b/projects/client/src/routes/shows/[slug]/living-poster/+page.svelte @@ -0,0 +1,16 @@ + + +