-
Notifications
You must be signed in to change notification settings - Fork 0
feat(content): add video teaser across all layers #65
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
Open
stacelKonrad
wants to merge
7
commits into
main
Choose a base branch
from
feat/video_teaser
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+368
−19
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
02fb14e
feat(content): add video teaser across all layers
stacelKonrad b8c5cec
refactor(content): use i18n for lazy video error message
stacelKonrad 45e9094
Merge branch 'main' into feat/video_teaser
stacelKonrad b6fd167
Merge branch 'main' into feat/video_teaser
stacelKonrad 7e6478f
refactor(content): improve video teaser link and migration structure
stacelKonrad 332aae3
Merge branch 'main' into feat/video_teaser
stacelKonrad 5fff1cd
fix(content): hide video link overlay when controls are active
stacelKonrad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,89 @@ | ||
| 'use client' | ||
|
|
||
| import { useRef, useState, useEffect } from 'react' | ||
| import { cn } from '@/lib/utils' | ||
| import { useTranslations } from 'next-intl' | ||
|
|
||
| interface LazyVideoProps { | ||
| src?: string | ||
| poster?: string | ||
| autoPlay?: boolean | ||
| muted?: boolean | ||
| controls?: boolean | ||
| eager?: boolean | ||
| className?: string | ||
| aspectRatio?: string | ||
| } | ||
|
|
||
| export function LazyVideo({ | ||
| src, | ||
| poster, | ||
| autoPlay, | ||
| muted, | ||
| controls = false, | ||
| eager = false, | ||
| className, | ||
| aspectRatio = '16 / 9', | ||
| }: LazyVideoProps) { | ||
| const ref = useRef<HTMLVideoElement>(null) | ||
| const [inView, setInView] = useState(eager) | ||
| const [loaded, setLoaded] = useState(false) | ||
| const [error, setError] = useState(false) | ||
| const t = useTranslations('teaser') | ||
|
|
||
| useEffect(() => { | ||
| if (inView) { | ||
| return | ||
| } | ||
| const el = ref.current | ||
| if (!el) { | ||
| return | ||
| } | ||
| const observer = new IntersectionObserver( | ||
| ([entry]) => { | ||
| if (entry?.isIntersecting) { | ||
| setInView(true) | ||
| observer.disconnect() | ||
| } | ||
| }, | ||
| { rootMargin: '200px' } | ||
| ) | ||
| observer.observe(el) | ||
| return () => observer.disconnect() | ||
| }, [inView]) | ||
|
|
||
| return ( | ||
| <div | ||
| className='relative w-full overflow-hidden rounded-lg' | ||
| style={{ aspectRatio }} | ||
| > | ||
| {!loaded && !error && ( | ||
| <div className='absolute inset-0 animate-pulse bg-gray-200' /> | ||
| )} | ||
| {error && ( | ||
| <div className='absolute inset-0 flex items-center justify-center bg-gray-100 text-sm text-gray-500'> | ||
| {t('video.unavailable')} | ||
| </div> | ||
| )} | ||
| {!error && ( | ||
| <video | ||
| ref={ref} | ||
| src={inView ? src : undefined} | ||
| poster={poster} | ||
| autoPlay={autoPlay} | ||
| muted={muted} | ||
| loop={autoPlay} | ||
| controls={controls} | ||
| preload='none' | ||
| playsInline={autoPlay && muted} | ||
| onCanPlay={() => setLoaded(true)} | ||
| onError={() => setError(true)} | ||
| className={cn( | ||
| 'absolute inset-0 h-full w-full object-cover', | ||
| className | ||
| )} | ||
| /> | ||
| )} | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or 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
31 changes: 31 additions & 0 deletions
31
apps/presentation/features/content/teasers/teaser-video-block.tsx
This file contains hidden or 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,31 @@ | ||
| import type { VideoTeaser } from '@core/contracts/content/teaser-video' | ||
| import { LazyVideo } from './lazy-video' | ||
| import { CmsLink } from '../cms-link' | ||
|
|
||
| interface TeaserVideoProps { | ||
| teaser: VideoTeaser | ||
| imagePreload?: boolean | ||
| } | ||
|
|
||
| export function TeaserVideoBlock({ teaser, imagePreload }: TeaserVideoProps) { | ||
| const { videoUrl, thumbnailUrl, autoplay, controls, link } = teaser | ||
| return ( | ||
| <div className='relative'> | ||
| {link && !controls && ( | ||
| <CmsLink | ||
| link={link} | ||
| className='absolute inset-0 z-10' | ||
| useLabelAsFallbackContent={false} | ||
| /> | ||
|
Collaborator
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.
Collaborator
Author
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. Introduced new prop to adjust this behavior |
||
| )} | ||
| <LazyVideo | ||
| src={videoUrl} | ||
| poster={thumbnailUrl} | ||
| autoPlay={autoplay} | ||
| muted={autoplay} | ||
| controls={controls} | ||
| eager={imagePreload} | ||
| /> | ||
| </div> | ||
| ) | ||
| } | ||
This file contains hidden or 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
17 changes: 17 additions & 0 deletions
17
apps/storybook/src/stories/teasers/teaser-video.stories.tsx
This file contains hidden or 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 type { Meta, StoryObj } from '@storybook/react' | ||
| import { TeaserVideoBlock } from '@/features/content/teasers/teaser-video-block' | ||
| import { VIDEO } from './teaser-mock-data' | ||
|
|
||
| const meta: Meta<typeof TeaserVideoBlock> = { | ||
| title: 'Teasers/Video', | ||
| component: TeaserVideoBlock, | ||
| tags: ['autodocs'], | ||
| parameters: { layout: 'padded' }, | ||
| } | ||
|
|
||
| export default meta | ||
| type Story = StoryObj<typeof meta> | ||
|
|
||
| export const Default: Story = { | ||
| args: { teaser: VIDEO }, | ||
| } |
This file contains hidden or 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,14 @@ | ||
| import { z } from 'zod' | ||
| import { CmsLinkSchema } from './cms-link' | ||
|
|
||
| export const VideoTeaserSchema = z.object({ | ||
| type: z.literal('video'), | ||
| title: z.string().optional(), | ||
| videoUrl: z.string().optional(), | ||
| thumbnailUrl: z.string().optional(), | ||
| autoplay: z.boolean(), | ||
| controls: z.boolean(), | ||
| caption: z.string().optional(), | ||
| link: CmsLinkSchema.optional(), | ||
| }) | ||
| export type VideoTeaser = z.infer<typeof VideoTeaserSchema> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
20 changes: 20 additions & 0 deletions
20
integrations/contentful-api/src/graphql/teaser-video.fragment.ts
This file contains hidden or 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,20 @@ | ||
| import { gql } from 'graphql-request' | ||
|
|
||
| export const TeaserVideoFragment = gql` | ||
| fragment TeaserVideoFragment on TeaserVideo { | ||
| __typename | ||
| title | ||
| video { | ||
| ...AssetFragment | ||
| } | ||
| thumbnail { | ||
| ...AssetFragment | ||
| } | ||
| autoplay | ||
| controls | ||
| caption | ||
| link { | ||
| ...LinkEntryFragment | ||
| } | ||
| } | ||
| ` |
This file contains hidden or 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
17 changes: 17 additions & 0 deletions
17
integrations/contentful-api/src/mappers/teaser/map-teaser-video.ts
This file contains hidden or 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 type { VideoTeaser } from '@core/contracts/content/teaser-video' | ||
| import type { TeaserVideoApiResponse } from '../../schemas/teaser/teaser-video' | ||
| import { mapLinkEntryToCmsLink } from '../cms-link' | ||
|
|
||
| /** Maps Contentful TeaserVideo entry to contract VideoTeaser. */ | ||
| export function mapTeaserVideo(entry: TeaserVideoApiResponse): VideoTeaser { | ||
| return { | ||
| type: 'video', | ||
| title: entry.title ?? undefined, | ||
| videoUrl: entry.video?.url ?? undefined, | ||
| thumbnailUrl: entry.thumbnail?.url ?? undefined, | ||
| autoplay: entry.autoplay ?? false, | ||
| controls: entry.controls ?? true, | ||
| caption: entry.caption ?? undefined, | ||
| link: mapLinkEntryToCmsLink(entry.link), | ||
| } | ||
| } |
This file contains hidden or 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
integrations/contentful-api/src/schemas/teaser/teaser-video.ts
This file contains hidden or 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 { z } from 'zod' | ||
| import { ContentfulImageApiResponseSchema } from '../image' | ||
| import { LinkEntryApiResponseSchema } from '../link' | ||
|
|
||
| export const TeaserVideoApiResponseSchema = z.object({ | ||
| __typename: z.literal('TeaserVideo'), | ||
| title: z.string().optional().nullable(), | ||
| video: ContentfulImageApiResponseSchema, | ||
| thumbnail: ContentfulImageApiResponseSchema.optional().nullable(), | ||
| autoplay: z.boolean().optional().nullable(), | ||
| controls: z.boolean().optional().nullable(), | ||
| caption: z.string().optional().nullable(), | ||
| link: LinkEntryApiResponseSchema.optional().nullable(), | ||
| }) | ||
|
|
||
| export type TeaserVideoApiResponse = z.infer< | ||
| typeof TeaserVideoApiResponseSchema | ||
| > |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think now we could have problems for combination of
linkandcontrolsas it wouldn't be possible to use controls at all due to overlay.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.
I blocked link display if controls are enabled