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

chore(Video): Conditionally Render Youtube/Vimeo Videos #3049

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

smithgajjar09
Copy link
Contributor

@smithgajjar09 smithgajjar09 commented Mar 11, 2025

Overview

Conditionally Render Youtube/Vimeo videos if captions provided or fallback to default embed

PR Checklist

  • Related to designs:
  • Related to JIRA ticket: WEB-3541
  • I have run this code to verify it works
  • This PR includes unit tests for the code change
  • This PR includes testing instructions tests for the code change
  • The alpha package of this PR is passing end-to-end tests in all relevant Codecademy repositories

Testing Instructions

Over here -> https://github.com/codecademy-engineering/mono/pull/9574

PR Links and Envs

Repository PR Link PR Env
Portal Portal Link Portal Env

Copy link

nx-cloud bot commented Mar 11, 2025

View your CI Pipeline Execution ↗ for commit f97d1f1.


☁️ Nx Cloud last updated this comment at 2025-03-24 08:26:29 UTC

@smithgajjar09 smithgajjar09 changed the title refactor(Video): Conditionally Render Youtube/Vimeo Videos chore(Video): Conditionally Render Youtube/Vimeo Videos Mar 11, 2025
@codecademydev
Copy link
Collaborator

📬Published Alpha Packages:

@codecademy/gamut@59.3.1-alpha.f97d1f.0
@codecademy/gamut-kit@0.6.488-alpha.f97d1f.0
@codecademy/styleguide@70.5.1-alpha.f97d1f.0

@codecademydev
Copy link
Collaborator

🚀 Styleguide deploy preview ready!

https://67e11747fa57695a3e1a0e4f--gamut-preview.netlify.app

Deploy Logs

@smithgajjar09 smithgajjar09 marked this pull request as ready for review March 24, 2025 17:46
@smithgajjar09 smithgajjar09 requested a review from a team as a code owner March 24, 2025 17:46
@@ -90,13 +91,43 @@ export const Video: React.FC<VideoProps> = (props) => {
},
};

const isExternallyHostedVideoUrl = (url: string): boolean =>
!!(url.match(/youtu(be\.com|\.be)/) || url.match(/vimeo.com/));
Copy link
Contributor

@LinKCoding LinKCoding Mar 25, 2025

Choose a reason for hiding this comment

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

for consistency, it should be vimeo\.com

But also wondering if the com or be is necessary? like is there any instance where a different domain is used, like .co.uk
Or is this always ok because the URL is set by a dev and they'll conform to using these domains?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not really sure, this is something we already had in monorepo/author so just to make sure nothing breaks I copied them over here without any change. I would guess dev confirms the URL in author preview which checks for these regex('s)

Copy link
Contributor

Choose a reason for hiding this comment

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

gotcha, alrighties then I'd say that the period should still be escaped in both places
vimeo.com => vimeo\.com
but nothing crazy :)

Comment on lines +97 to +111
const isExternallyHostedVideo = (videoUrl: PlayerSrc): boolean => {
if (!videoUrl) return false;

if (typeof videoUrl === 'string') {
return isExternallyHostedVideoUrl(videoUrl);
}

if (Array.isArray(videoUrl)) {
return videoUrl.some(
(url) => typeof url === 'string' && isExternallyHostedVideoUrl(url)
);
}

return false;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of this being based on the hosting site, can we have it based on if captions are provided or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have that check combined with this one -> Here (line 113-130)

So basically it checks if video source is youtube/vimeo and if captions are not provided we render ReactPlayer. This is because we also have few videos hosted on our S3 which gets rendered in HTML 5 player right now and this logic handles those videos to be able to render in new player -> Example

Do we want to switch all videos to ReactPlayer if captions are not provided ?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah gotcha! that makes sense, i just misread the logic here

Copy link
Contributor

@LinKCoding LinKCoding left a comment

Choose a reason for hiding this comment

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

left a note about the regex but LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants