Skip to content
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

fix: redirect to watch youtube video without consent #4117

Merged
merged 5 commits into from
Jan 28, 2025
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
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}
/>
ilasw marked this conversation as resolved.
Show resolved Hide resolved
</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';
sshanzel marked this conversation as resolved.
Show resolved Hide resolved
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"
sshanzel marked this conversation as resolved.
Show resolved Hide resolved
rel={anchorDefaultRel}
>
Watch on YouTube
</Button>
Expand Down
Loading