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

feat: integrate Wistia analytics in Video Learning Hub page #2435

Merged
merged 1 commit into from
Apr 16, 2024
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
7 changes: 6 additions & 1 deletion src/components/marketing/LearningHub/FeaturedVideos.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useMediaQuery from '@mui/material/useMediaQuery';
* Components Imports
*/
import VideoCard from './FeaturedCard';
import WistiaVideoCard from './FeaturedWistiaCard';

/**
* React Imports
Expand Down Expand Up @@ -51,7 +52,11 @@ const FeaturedVideos = ({ title, featuredVideos = [] }) => {
return (
<Grid key={idx} item xs={12} md={6} lg={4}>
<Box sx={{ textDecoration: 'none' }}>
<VideoCard {...item} />
{item?.youtube_link ? (
<VideoCard {...item} />
) : (
<WistiaVideoCard {...item} />
)}
</Box>
</Grid>
);
Expand Down
96 changes: 96 additions & 0 deletions src/components/marketing/LearningHub/FeaturedWistiaCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* MUI Imports
*/
import { Box, Card, Typography } from '@mui/material';
import { useTheme } from '@mui/material/styles';
import { useEffect } from 'react';

const WistiaVideoCard = ({
title,
wistia_video_id,
published_date,
video_length,
}) => {
const theme = useTheme();

const formatDate = (date) => {
date = new Date(date);
const options = { year: 'numeric', month: 'long', day: 'numeric' };
return date.toLocaleDateString('en-US', options);
};

useEffect(() => {
const script1 = document.createElement('script');
script1.src = `https://fast.wistia.com/embed/medias/${wistia_video_id}.jsonp`;
script1.async = true;

const script2 = document.createElement('script');
script2.src = 'https://fast.wistia.com/assets/external/E-v1.js';
script2.async = true;

document.body.appendChild(script1);
document.body.appendChild(script2);

return () => {
document.body.removeChild(script1);
document.body.removeChild(script2);
};
}, [wistia_video_id]);

return (
<Box sx={{ textDecoration: 'none' }}>
<Card
sx={{
'&:hover': {
border: `1px solid ${theme.palette.zesty.zestyOrange}`,
},
margin: 'auto',
width: '100%',
minHeight: 280,
background: '#000',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
border:
theme.palette.mode === 'light' &&
`1px solid ${theme.palette.common.grey}`,
}}
>
<Box
sx={{
position: 'relative',
overflow: 'hidden',
paddingTop: '56.25%',
height: '100%',
width: '100%',
}}
>
<Box
className={`wistia_embed wistia_async_${wistia_video_id} popover=true videoFoam=true`}
sx={{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
}}
/>
</Box>
</Card>

<Typography component="h4" variant="body1" sx={{ fontWeight: 'bold' }}>
{title}
</Typography>
{video_length && (
<Typography component="p" variant="subtitle2">
{video_length}
</Typography>
)}
<Typography component="p" variant="subtitle2">
{formatDate(published_date)}
</Typography>
</Box>
);
};

export default WistiaVideoCard;
20 changes: 17 additions & 3 deletions src/components/marketing/LearningHub/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import CloseIcon from '@mui/icons-material/Close';
/**
* React Imports
*/
import { useContext } from 'react';
import { useContext, useEffect } from 'react';
import { LearningHubVideosContext } from './context/LearningHubVideosContext';

const Filters = ({ featuredCards, tags }) => {
Expand All @@ -33,6 +33,16 @@ const Filters = ({ featuredCards, tags }) => {
LearningHubVideosContext,
);

const scrollToVideos = () => {
document.getElementById('scrollTop').scrollIntoView({ behavior: 'smooth' });
};

useEffect(() => {
if (selectedTags) {
scrollToVideos();
}
}, [selectedTags]);

return (
<Container>
<Grid
Expand Down Expand Up @@ -73,7 +83,9 @@ const Filters = ({ featuredCards, tags }) => {
? theme.palette.zesty.zestyBlue
: theme.palette.background.paper,
}}
onClick={() => setSelectedTags(item.title)}
onClick={() => {
setSelectedTags(item.title);
}}
>
<Typography
sx={{
Expand Down Expand Up @@ -122,7 +134,9 @@ const Filters = ({ featuredCards, tags }) => {
{tags.map((item, idx) => (
<Grid key={idx} item sm={6} md={4} lg={2}>
<Box
onClick={() => setSelectedTags(item.tag_name)}
onClick={() => {
setSelectedTags(item.tag_name);
}}
sx={{
textDecoration: 'none',
border: item.isActive
Expand Down
2 changes: 1 addition & 1 deletion src/views/zesty/LearningHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function LearningHub({ content }) {
<Box sx={{ pt: 10 }}>
<FeaturedVideos
title="Featured Videos"
featuredVideos={content?.featured_videos?.data}
featuredVideos={content?.featured_wistia_videos?.data}
/>
</Box>
<MainVideos withPagination={true} />
Expand Down
Loading