Skip to content

Commit

Permalink
fix: redirect to watch youtube video without consent (#4117)
Browse files Browse the repository at this point in the history
  • Loading branch information
sshanzel authored Jan 28, 2025
1 parent a261a27 commit 3163739
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
5 changes: 1 addition & 4 deletions packages/shared/src/components/post/PostContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,9 @@ export function PostContentRaw({
</div>
{isVideoType && (
<YoutubeVideo
title={title}
placeholderProps={{ post, onWatchVideo: onReadArticle }}
videoId={post.videoId}
className="mb-7"
image={post.image}
source={post.source}
onWatchVideo={onReadArticle}
/>
)}
{post.summary && (
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/src/components/post/ShareYouTubeContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ function ShareYouTubeContent({
)}
>
<YoutubeVideo
title={post?.sharedPost?.title}
videoId={post?.sharedPost?.videoId}
image={post?.sharedPost?.image}
source={post?.sharedPost?.source}
onWatchVideo={onReadArticle}
placeholderProps={{
post: post.sharedPost,
onWatchVideo: onReadArticle,
}}
/>
</SharedLinkContainer>
</>
Expand Down
7 changes: 4 additions & 3 deletions packages/shared/src/components/video/YoutubeVideo.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ const renderComponent = (): RenderResult => {
return render(
<TestBootProvider client={client}>
<YoutubeVideo
title="test title"
placeholderProps={{
post: { ...sharePost, title: 'test title' },
onWatchVideo: jest.fn(),
}}
videoId="igZCEr3HwCg"
data-testid="iframeId"
image={sharePost.image}
source={sharePost.source}
/>
</TestBootProvider>,
);
Expand Down
27 changes: 11 additions & 16 deletions packages/shared/src/components/video/YoutubeVideo.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
import type { ReactElement } from 'react';
import type { HTMLAttributes, ReactElement } from 'react';
import React from 'react';
import { useAuthContext } from '../../contexts/AuthContext';
import { GdprConsentKey } from '../../hooks/useCookieBanner';
import type { Source } from '../../graphql/sources';
import type { YoutubeVideoWithoutConsentProps } from './YoutubeVideoWithoutConsent';
import { YoutubeVideoWithoutConsent } from './YoutubeVideoWithoutConsent';
import { YoutubeVideoBackground, YoutubeVideoContainer } from './common';
import { useConsentCookie } from '../../hooks/useCookieConsent';

interface YoutubeVideoProps {
interface YoutubeVideoProps extends HTMLAttributes<HTMLIFrameElement> {
videoId: string;
className?: string;
title: string;
image: string;
source: Source;
onWatchVideo?: () => void;
placeholderProps: Pick<
YoutubeVideoWithoutConsentProps,
'post' | 'onWatchVideo'
>;
}

const YoutubeVideo = ({
videoId,
className,
title,
image,
source,
onWatchVideo,
placeholderProps,
...props
}: YoutubeVideoProps): ReactElement => {
const { title } = placeholderProps.post;
const { isAuthReady, isGdprCovered } = useAuthContext();
const { cookieExists, saveCookies } = useConsentCookie(
GdprConsentKey.Marketing,
Expand All @@ -41,10 +39,7 @@ const YoutubeVideo = ({
if (isGdprCovered && !cookieExists) {
return (
<YoutubeVideoWithoutConsent
title={title}
image={image}
source={source}
onWatchVideo={onWatchVideo}
{...placeholderProps}
onAcceptCookies={saveCookies}
/>
);
Expand All @@ -53,12 +48,12 @@ const YoutubeVideo = ({
return (
<YoutubeVideoContainer className={className}>
<iframe
{...props}
title={title}
src={`https://www.youtube-nocookie.com/embed/${videoId}`}
allow="autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share"
allowFullScreen
className="absolute inset-0 aspect-video w-full border-0"
{...props}
/>
</YoutubeVideoContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import { Typography, TypographyType } from '../typography/Typography';
import { Button, ButtonSize, ButtonVariant } from '../buttons/Button';
import { PlayIcon } from '../icons';
import classed from '../../lib/classed';
import type { Source } from '../../graphql/sources';
import type { Post } from '../../graphql/posts';
import { anchorDefaultRel } from '../../lib/strings';

interface YoutubeVideoWithoutConsentProps {
export interface YoutubeVideoWithoutConsentProps {
post: Post;
className?: string;
title: string;
image: string;
source: Source;
onWatchVideo: () => void;
onAcceptCookies: () => void;
}
Expand All @@ -29,12 +28,12 @@ const Background = classed(

export function YoutubeVideoWithoutConsent({
className,
image,
title,
source,
onWatchVideo,
onAcceptCookies,
post,
}: YoutubeVideoWithoutConsentProps): ReactElement {
const { title, image, source, permalink } = post;

return (
<Container className={classNames(className, 'relative')}>
<img
Expand Down Expand Up @@ -71,6 +70,10 @@ export function YoutubeVideoWithoutConsent({
className="mx-auto w-fit"
size={ButtonSize.Small}
onClick={onWatchVideo}
tag="a"
href={permalink}
target="_blank"
rel={anchorDefaultRel}
>
Watch on YouTube
</Button>
Expand Down

0 comments on commit 3163739

Please sign in to comment.