Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions projects/client/i18n/meta/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
});
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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');
});
});
Original file line number Diff line number Diff line change
@@ -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';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<script lang="ts">
import CrossOriginImage from "$lib/features/image/components/CrossOriginImage.svelte";
import { FeatureFlag } from "$lib/features/feature-flag/models/FeatureFlag";
import * as m from "$lib/features/i18n/messages";
import RenderForFeature from "$lib/guards/RenderForFeature.svelte";
import { useMedia, WellKnownMediaQuery } from "$lib/stores/css/useMedia";
import { isLivingPosterAvailable } from "../_internal/isLivingPosterAvailable";
import { toFullScreenPosterView } from "../_internal/toFullScreenPosterView";
import type { LivingPosterTarget } from "../models/LivingPosterTarget";
import LivingPoster from "./LivingPoster.svelte";

const {
target,
poster,
}: {
target: LivingPosterTarget | null | undefined;
poster: { src: string; alt: string } | null | undefined;
} = $props();

const isReducedMotion = useMedia(WellKnownMediaQuery.reducedMotion);

const view = $derived.by(() => {
const isReduced = $isReducedMotion;
if (!target) return null;

return isLivingPosterAvailable(target).then((isAvailable) =>
toFullScreenPosterView({ isAvailable, isReducedMotion: isReduced }),
);
});

let isSettled = $state(false);
</script>

<div class="trakt-full-screen-living-poster">
<div class="full-screen-poster-still" class:is-settled={isSettled}>
{#if poster}
<CrossOriginImage src={poster.src} alt={poster.alt} loading="eager" />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prioritize the full-screen hero image

On a direct visit this still poster is the page's hero/LCP image, but it opts into eager loading without fetchpriority="high"; after the summary request resolves, the browser can therefore schedule the only visible image at its default priority. Pass high fetch priority at this call site, as the existing summary poster does for priority images. .agents/rules/performance.mdL348-L354

Useful? React with 👍 / 👎.

{/if}
</div>

<RenderForFeature flag={FeatureFlag.LivingPoster} audience="director">
{#snippet enabled()}
{#if target && view}
{#await view then resolved}
{#if resolved === "live"}
<LivingPoster
{target}
onsettledchange={(settled) => (isSettled = settled)}
/>
{:else if resolved === "reduced-motion"}
<p class="full-screen-poster-note small">
{m.text_living_poster_reduced_motion()}
</p>
{:else}
<p class="full-screen-poster-note small">
{m.text_living_poster_unavailable()}
</p>
{/if}
{/await}
{/if}
{/snippet}

<p class="full-screen-poster-note small">
{m.text_living_poster_unavailable()}
</p>
</RenderForFeature>
</div>

<style>
.trakt-full-screen-living-poster {
--poster-aspect-ratio: 2 / 3;

position: relative;
width: min(100vw, calc(100dvh * 2 / 3));
aspect-ratio: var(--poster-aspect-ratio);
}

.full-screen-poster-still {
position: absolute;
inset: 0;

&.is-settled {
opacity: 0;
}

:global(img) {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
border-radius: var(--border-radius-xxl);
box-shadow: var(--shadow-raised);
}
}

.full-screen-poster-note {
position: absolute;
z-index: var(--layer-raised);
inset-inline: var(--gap-m);
inset-block-end: var(--gap-m);

margin: 0;
padding: var(--gap-xs) var(--gap-s);
border-radius: var(--border-radius-m);
text-align: center;

color: var(--shade-10);
background: color-mix(in srgb, var(--shade-1000) 72%, transparent);
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<script lang="ts">
import { goto } from "$app/navigation";
import ActionButton from "$lib/components/buttons/ActionButton.svelte";
import CloseIcon from "$lib/components/icons/CloseIcon.svelte";
import FullScreenLivingPoster from "$lib/features/living-poster/components/FullScreenLivingPoster.svelte";
import * as m from "$lib/features/i18n/messages";
import type { MediaEntry } from "$lib/requests/models/MediaEntry";
import type { MediaType } from "$lib/requests/models/MediaType";
import { UrlBuilder } from "$lib/utils/url/UrlBuilder";
import TraktPage from "../layout/TraktPage.svelte";
import NavbarStateSetter from "../navbar/NavbarStateSetter.svelte";

const {
type,
slug,
media,
}: {
type: MediaType;
slug: string;
media: MediaEntry | null | undefined;
} = $props();

const closeHref = $derived(UrlBuilder.media(type, media?.slug ?? slug));

const target = $derived(media && { type, id: media.id });

const poster = $derived(
media && { src: media.poster.url.medium, alt: media.title },
);

const onkeydown = (event: KeyboardEvent) => {
if (event.key !== "Escape") return;

// eslint-disable-next-line svelte/no-navigation-without-resolve
goto(closeHref);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Close the poster without adding another history entry

When this route is reached from a title page, both this goto and the close button's ordinary link push the title URL as a new entry instead of closing the current entry. Pressing browser Back after closing therefore reopens the living-poster page, producing a navigation loop; use back/replace semantics consistently for both close paths.

Useful? React with 👍 / 👎.

};

let stage: HTMLDivElement | undefined = $state();

$effect(() => {
stage?.focus({ preventScroll: true });
});
</script>

<TraktPage
audience="all"
title={media?.title}
image={media?.poster.url.thumb}
mode="content-only"
isIndexable={false}
>
<NavbarStateSetter mode="hidden" />

<div
class="trakt-living-poster-page"
data-theme="dark"
role="dialog"
aria-modal="true"
aria-label={media?.title}
tabindex="-1"
bind:this={stage}
{onkeydown}
>
<div class="living-poster-page-close">
<ActionButton
href={closeHref}
label={m.button_label_close()}
variant="secondary"
style="ghost"
>
<CloseIcon />
</ActionButton>
</div>

<FullScreenLivingPoster {target} {poster} />
</div>
</TraktPage>

<style>
.trakt-living-poster-page {
position: fixed;
inset: 0;
z-index: var(--layer-dialog);

display: grid;
place-items: center;

background: var(--shade-1000);
outline: none;
}

.living-poster-page-close {
position: absolute;
z-index: var(--layer-raised);
inset-block-start: calc(var(--gap-m) + env(safe-area-inset-top));
inset-inline-start: var(--gap-m);
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script lang="ts">
import { useQuery } from "$lib/features/query/useQuery";
import { movieSummaryQuery } from "$lib/requests/queries/movies/movieSummaryQuery";
import LivingPosterPage from "$lib/sections/living-poster/LivingPosterPage.svelte";
import { fromRune } from "$lib/utils/store/fromRune.svelte";
import { map } from "rxjs";
import type { PageProps } from "./$types";

const { params }: PageProps = $props();

const movie = useQuery(
fromRune(() => params.slug).pipe(
map((slug) => movieSummaryQuery({ slug })),
),
);
</script>

<LivingPosterPage type="movie" slug={params.slug} media={$movie.data} />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Wire the full-screen route into the summary UI

A repo-wide search for living-poster finds only these new route definitions and their implementation, with no link or URL builder from either movie or show summary. Consequently directors cannot discover or open this feature through the application—the existing summary poster remains inert or retains its trailer/streaming link—so an appropriately gated summary control needs to navigate to this route.

Useful? React with 👍 / 👎.

16 changes: 16 additions & 0 deletions projects/client/src/routes/shows/[slug]/living-poster/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
import { useQuery } from "$lib/features/query/useQuery";
import { showSummaryQuery } from "$lib/requests/queries/shows/showSummaryQuery";
import LivingPosterPage from "$lib/sections/living-poster/LivingPosterPage.svelte";
import { fromRune } from "$lib/utils/store/fromRune.svelte";
import { map } from "rxjs";
import type { PageProps } from "./$types";

const { params }: PageProps = $props();

const show = useQuery(
fromRune(() => params.slug).pipe(map((slug) => showSummaryQuery({ slug }))),
);
</script>

<LivingPosterPage type="show" slug={params.slug} media={$show.data} />
Loading