Repository navigation
feat(summary): open a title's living poster full screen #3898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" /> | ||
| {/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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When this route is reached from a title page, both this 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} /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A repo-wide search for Useful? React with 👍 / 👎. |
||
| 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} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-L354Useful? React with 👍 / 👎.