From 2a8b9f1e2c133aa1b9f6618189d91d90e3476213 Mon Sep 17 00:00:00 2001 From: Nikolai Berestevich Date: Wed, 25 Aug 2021 16:33:23 +0300 Subject: [PATCH 1/8] nikolai.berestevich/feat/blog-all-videos-from-cms --- src/pages/blog/_video-player.js | 2 +- src/pages/blog/videos/_all-videos.js | 27 ++++++-- src/pages/blog/videos/_data.js | 92 --------------------------- src/pages/blog/videos/_video-card.js | 22 +++---- src/pages/blog/videos/index.js | 95 ++++++++++++++++++++-------- 5 files changed, 100 insertions(+), 138 deletions(-) delete mode 100644 src/pages/blog/videos/_data.js diff --git a/src/pages/blog/_video-player.js b/src/pages/blog/_video-player.js index 749e86fedee..277e37d1836 100644 --- a/src/pages/blog/_video-player.js +++ b/src/pages/blog/_video-player.js @@ -138,7 +138,7 @@ const VideoPlayer = ({ video_src, closeVideo }) => { VideoPlayer.propTypes = { closeVideo: PropTypes.func, - video_src: PropTypes.object, + video_src: PropTypes.string, } export default VideoPlayer diff --git a/src/pages/blog/videos/_all-videos.js b/src/pages/blog/videos/_all-videos.js index 05e6e392a53..061dd0bac8b 100644 --- a/src/pages/blog/videos/_all-videos.js +++ b/src/pages/blog/videos/_all-videos.js @@ -9,11 +9,23 @@ import RightArrow from 'images/svg/black-right-arrow.svg' const AllVideos = ({ video_data }) => { const [show, setShow] = useState(false) + const [play_video_id, setPlayVideoId] = useState('') useEffect(() => { show ? (document.body.style.overflow = 'hidden') : (document.body.style.overflow = 'unset') }, [show]) + const play_video_src = `http://cms.deriv.cloud/assets/${play_video_id}` + + const openVideo = (video_id) => { + setPlayVideoId(video_id) + setShow(true) + } + + const closeVideo = () => { + setShow(false) + setPlayVideoId('') + } return ( @@ -25,15 +37,16 @@ const AllVideos = ({ video_data }) => { {video_data.map((item) => { - return setShow(true)} /> + return ( + openVideo(item.video_file.id)} + /> + ) })} - {show && ( - setShow(false)} - /> - )} + {show && } ) } diff --git a/src/pages/blog/videos/_data.js b/src/pages/blog/videos/_data.js deleted file mode 100644 index f28200871c8..00000000000 --- a/src/pages/blog/videos/_data.js +++ /dev/null @@ -1,92 +0,0 @@ -export const video_data = [ - { - image: 'https://source.unsplash.com/random/1', - video_duration: '1:20', - category: ['Multipliers', 'CFD', 'Stocks', 'Forex', 'Category', 'Sixth'], - title: 'How to trade multipliers on Deriv', - description: - 'To help you begin, we will look at the basics of cryptocurrency: what it is, how it works, and how to start trading cryptos on Deriv.com.', - date: '12 June 2021', - id: 1, - }, - { - image: 'https://source.unsplash.com/random/2', - video_duration: '1:20', - category: ['Multipliers'], - title: 'How to trade multipliers on Deriv this is for testing much much longer titles', - description: - 'To help you begin, we will look at the basics of cryptocurrency: what it is, how it works, and how to start trading cryptos on Deriv.com.', - date: '12 June 2021', - id: 2, - }, - { - image: 'https://source.unsplash.com/random/3', - video_duration: '1:20', - category: ['Multipliers'], - title: 'How to trade multipliers on Deriv', - description: - 'To help you begin, we will look at the basics of cryptocurrency: what it is, how it works, and how to start trading cryptos on Deriv.com.', - date: '12 June 2021', - id: 3, - }, - { - image: 'https://source.unsplash.com/random/4', - video_duration: '1:20', - category: ['Multipliers'], - title: 'How to trade multipliers on Deriv', - description: - 'To help you begin, we will look at the basics of cryptocurrency: what it is, how it works, and how to start trading cryptos on Deriv.com.', - date: '12 June 2021', - id: 4, - }, - { - image: 'https://source.unsplash.com/random/5', - video_duration: '1:20', - category: ['Multipliers'], - title: 'How to trade multipliers on Deriv', - description: - 'To help you begin, we will look at the basics of cryptocurrency: what it is, how it works, and how to start trading cryptos on Deriv.com.', - date: '12 June 2021', - id: 5, - }, - { - image: 'https://source.unsplash.com/random/6', - video_duration: '1:20', - category: ['Multipliers'], - title: 'How to trade multipliers on Deriv', - description: - 'To help you begin, we will look at the basics of cryptocurrency: what it is, how it works, and how to start trading cryptos on Deriv.com.', - date: '12 June 2021', - id: 6, - }, - { - image: 'https://source.unsplash.com/random/7', - video_duration: '1:20', - category: ['Multipliers'], - title: 'How to trade multipliers on Deriv', - description: - 'To help you begin, we will look at the basics of cryptocurrency: what it is, how it works, and how to start trading cryptos on Deriv.com.', - date: '12 June 2021', - id: 7, - }, - { - image: 'https://source.unsplash.com/random/8', - video_duration: '1:20', - category: ['Multipliers'], - title: 'How to trade multipliers on Deriv', - description: - 'To help you begin, we will look at the basics of cryptocurrency: what it is, how it works, and how to start trading cryptos on Deriv.com.', - date: '12 June 2021', - id: 8, - }, - { - image: 'https://source.unsplash.com/random/9', - video_duration: '1:20', - category: ['Multipliers'], - title: 'How to trade multipliers on Deriv', - description: - 'To help you begin, we will look at the basics of cryptocurrency: what it is, how it works, and how to start trading cryptos on Deriv.com.', - date: '12 June 2021', - id: 9, - }, -] diff --git a/src/pages/blog/videos/_video-card.js b/src/pages/blog/videos/_video-card.js index cb6c8ea0479..f590b0ee282 100644 --- a/src/pages/blog/videos/_video-card.js +++ b/src/pages/blog/videos/_video-card.js @@ -1,8 +1,8 @@ import React from 'react' import PropTypes from 'prop-types' import styled from 'styled-components' -import { ContainedImg } from '../common/_styles' -import { Header } from 'components/elements' +import { getImage } from 'gatsby-plugin-image' +import { Header, QueryImage } from 'components/elements' import { Flex } from 'components/containers' import device from 'themes/device' import Triangle from 'images/svg/triangle.svg' @@ -118,14 +118,14 @@ const VideoCard = ({ item, openVideo }) => { - {item.category.slice(0, 2).map((item_category) => ( - - {item_category} + {item.tags.slice(0, 2).map((tag) => ( + + {tag.tags_id.tag_name} ))} - {item.category.length > 2 && ( + {item.tags.length > 2 && ( - {`+${item.category.slice(2).length.toString()}`} + {`+${item.tags.slice(2).length.toString()}`} )} @@ -134,14 +134,14 @@ const VideoCard = ({ item, openVideo }) => { {item.video_duration} - +
- {item.title} + {item.video_title}
- {item.date} + {item.published_date}
@@ -150,7 +150,7 @@ const VideoCard = ({ item, openVideo }) => { } VideoCard.propTypes = { - item: PropTypes.Object, + item: PropTypes.object, openVideo: PropTypes.func, } diff --git a/src/pages/blog/videos/index.js b/src/pages/blog/videos/index.js index 25be55fbb3e..ff7c1f5e25d 100644 --- a/src/pages/blog/videos/index.js +++ b/src/pages/blog/videos/index.js @@ -1,8 +1,9 @@ import React from 'react' import styled from 'styled-components' +import PropTypes from 'prop-types' +import { graphql } from 'gatsby' import Subscribe from '../components/_subscribe' import AllVideos from './_all-videos' -import { video_data } from './_data' import Layout from 'components/layout/layout' import { SEO, Container, Flex } from 'components/containers' import { Header } from 'components/elements' @@ -49,31 +50,71 @@ const StyledHeader = styled(Header)` } ` -const VideosPage = () => ( - - - - -
- Video tutorials -
- - Our latest videos and webinars - -
-
- - - - - - -
-) +const VideosPage = ({ data }) => { + const video_data = data.directus.videos + return ( + + + + +
+ Video tutorials +
+ + Our latest videos and webinars + +
+
+ {video_data && } + + + + + +
+ ) +} + +VideosPage.propTypes = { + data: PropTypes.object, +} export default WithIntl()(VideosPage) + +export const query = graphql` + query AllVideosQuery { + directus { + videos(filter: { status: { _eq: "published" } }, sort: "- published_date") { + video_id + video_slug + video_title + published_date + video_description + video_duration + tags { + tags_id { + tag_name + id + } + } + video_file { + id + } + video_thumbnail { + id + imageFile { + id + childImageSharp { + gatsbyImageData + } + } + } + } + } + } +` From 68711ad856d1fc623a9ae741bd04c0ff47878aae Mon Sep 17 00:00:00 2001 From: Nikolai Berestevich Date: Wed, 25 Aug 2021 17:00:19 +0300 Subject: [PATCH 2/8] nikolai.berestevich/feat/blog-all-videos-from-cms --- src/pages/blog/videos/_video-card.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pages/blog/videos/_video-card.js b/src/pages/blog/videos/_video-card.js index f590b0ee282..13d1a04e0d5 100644 --- a/src/pages/blog/videos/_video-card.js +++ b/src/pages/blog/videos/_video-card.js @@ -118,11 +118,12 @@ const VideoCard = ({ item, openVideo }) => { - {item.tags.slice(0, 2).map((tag) => ( - - {tag.tags_id.tag_name} - - ))} + {item.tags && + item.tags.slice(0, 2).map((tag) => ( + + {tag.tags_id.tag_name} + + ))} {item.tags.length > 2 && ( {`+${item.tags.slice(2).length.toString()}`} @@ -134,7 +135,10 @@ const VideoCard = ({ item, openVideo }) => { {item.video_duration} - +
From 0d5489b80ee44ae8a9932c521f1ea397d808b324 Mon Sep 17 00:00:00 2001 From: Nikolai Berestevich Date: Wed, 25 Aug 2021 17:17:46 +0300 Subject: [PATCH 3/8] nikolai.berestevich/feat/blog-all-videos-from-cms --- src/pages/blog/videos/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/blog/videos/index.js b/src/pages/blog/videos/index.js index ff7c1f5e25d..b875dddd042 100644 --- a/src/pages/blog/videos/index.js +++ b/src/pages/blog/videos/index.js @@ -52,7 +52,7 @@ const StyledHeader = styled(Header)` const VideosPage = ({ data }) => { const video_data = data.directus.videos - + console.log(data.directus.videos) return ( Date: Wed, 25 Aug 2021 17:18:12 +0300 Subject: [PATCH 4/8] nikolai.berestevich/feat/blog-all-videos-from-cms --- src/pages/blog/videos/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/blog/videos/index.js b/src/pages/blog/videos/index.js index b875dddd042..ff7c1f5e25d 100644 --- a/src/pages/blog/videos/index.js +++ b/src/pages/blog/videos/index.js @@ -52,7 +52,7 @@ const StyledHeader = styled(Header)` const VideosPage = ({ data }) => { const video_data = data.directus.videos - console.log(data.directus.videos) + return ( Date: Thu, 26 Aug 2021 15:46:10 +0300 Subject: [PATCH 5/8] nikolai.berestevich/feat/empty blog -all videos from cms --- src/pages/blog/articles/_article-card.js | 2 ++ src/pages/blog/videos/_video-card.js | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pages/blog/articles/_article-card.js b/src/pages/blog/articles/_article-card.js index 43823ced649..590a5bb8103 100644 --- a/src/pages/blog/articles/_article-card.js +++ b/src/pages/blog/articles/_article-card.js @@ -69,6 +69,8 @@ const ArticleCard = ({ item }) => { diff --git a/src/pages/blog/videos/_video-card.js b/src/pages/blog/videos/_video-card.js index 13d1a04e0d5..71003554930 100644 --- a/src/pages/blog/videos/_video-card.js +++ b/src/pages/blog/videos/_video-card.js @@ -1,7 +1,7 @@ import React from 'react' import PropTypes from 'prop-types' import styled from 'styled-components' -import { getImage } from 'gatsby-plugin-image' +// import { getImage } from 'gatsby-plugin-image' import { Header, QueryImage } from 'components/elements' import { Flex } from 'components/containers' import device from 'themes/device' @@ -37,7 +37,6 @@ const ImageWrapper = styled.div` width: 384px; position: relative; z-index: 1; - overflow: hidden; @media ${device.mobileL} { width: 100%; @@ -136,8 +135,10 @@ const VideoCard = ({ item, openVideo }) => { {item.video_duration} From a44cdfc5fbc73d1a71d0c517a3a8ebe500cab0ac Mon Sep 17 00:00:00 2001 From: Nikolai Berestevich Date: Fri, 27 Aug 2021 09:14:45 +0300 Subject: [PATCH 6/8] nikolai.berestevich/feat/empty blog -all videos from cms --- src/common/utility.js | 25 +++++++++++++++++++++++++ src/pages/blog/videos/_video-card.js | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/common/utility.js b/src/common/utility.js index b72b559eb7f..0a77c1ac92c 100644 --- a/src/common/utility.js +++ b/src/common/utility.js @@ -23,6 +23,31 @@ export const toISOFormat = (date) => { return '' } +export const ChangeDateFormat = (date) => { + const months = [ + 'January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December', + ] + try { + const day = date.slice(8) + const month = date.slice(5, 7) + const year = date.slice(0, 4) + return `${day} ${months[month - 1]} ${year}` + } catch { + return 'wrong format of input data' + } +} + export const toHashFormat = (string) => string.replace(/\s+/g, '-').toLowerCase() // change space to dash then lowercase all export const isBrowser = () => typeof window !== 'undefined' diff --git a/src/pages/blog/videos/_video-card.js b/src/pages/blog/videos/_video-card.js index 71003554930..a64bc7ab205 100644 --- a/src/pages/blog/videos/_video-card.js +++ b/src/pages/blog/videos/_video-card.js @@ -1,8 +1,8 @@ import React from 'react' import PropTypes from 'prop-types' import styled from 'styled-components' -// import { getImage } from 'gatsby-plugin-image' import { Header, QueryImage } from 'components/elements' +import { ChangeDateFormat } from 'common/utility' import { Flex } from 'components/containers' import device from 'themes/device' import Triangle from 'images/svg/triangle.svg' @@ -146,7 +146,7 @@ const VideoCard = ({ item, openVideo }) => { {item.video_title}
- {item.published_date} + {ChangeDateFormat(item.published_date)}
From 48e73d2601555c6533166b0fcecbfe032d2b58b8 Mon Sep 17 00:00:00 2001 From: Nikolai Berestevich Date: Fri, 27 Aug 2021 10:15:56 +0300 Subject: [PATCH 7/8] nikolai.berestevich/feat/empty blog -all videos from cms --- src/common/utility.js | 25 ------------------------- src/pages/blog/videos/_video-card.js | 4 ++-- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/src/common/utility.js b/src/common/utility.js index 0a77c1ac92c..b72b559eb7f 100644 --- a/src/common/utility.js +++ b/src/common/utility.js @@ -23,31 +23,6 @@ export const toISOFormat = (date) => { return '' } -export const ChangeDateFormat = (date) => { - const months = [ - 'January', - 'February', - 'March', - 'April', - 'May', - 'June', - 'July', - 'August', - 'September', - 'October', - 'November', - 'December', - ] - try { - const day = date.slice(8) - const month = date.slice(5, 7) - const year = date.slice(0, 4) - return `${day} ${months[month - 1]} ${year}` - } catch { - return 'wrong format of input data' - } -} - export const toHashFormat = (string) => string.replace(/\s+/g, '-').toLowerCase() // change space to dash then lowercase all export const isBrowser = () => typeof window !== 'undefined' diff --git a/src/pages/blog/videos/_video-card.js b/src/pages/blog/videos/_video-card.js index a64bc7ab205..5f198948d0f 100644 --- a/src/pages/blog/videos/_video-card.js +++ b/src/pages/blog/videos/_video-card.js @@ -2,7 +2,7 @@ import React from 'react' import PropTypes from 'prop-types' import styled from 'styled-components' import { Header, QueryImage } from 'components/elements' -import { ChangeDateFormat } from 'common/utility' +// import { convertDate } from 'common/utility' import { Flex } from 'components/containers' import device from 'themes/device' import Triangle from 'images/svg/triangle.svg' @@ -146,7 +146,7 @@ const VideoCard = ({ item, openVideo }) => { {item.video_title}
- {ChangeDateFormat(item.published_date)} + {/* {convertDate(item.published_date)} */}
From 32325f5fa13c609ee68a908207ee8da4f945a164 Mon Sep 17 00:00:00 2001 From: Nikolai Berestevich Date: Fri, 27 Aug 2021 10:44:04 +0300 Subject: [PATCH 8/8] nikolai.berestevich/feat/empty blog -all videos from cms --- src/pages/blog/videos/_video-card.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pages/blog/videos/_video-card.js b/src/pages/blog/videos/_video-card.js index 56d50c8a5b0..ee2995b7ed1 100644 --- a/src/pages/blog/videos/_video-card.js +++ b/src/pages/blog/videos/_video-card.js @@ -109,6 +109,9 @@ const ContentWrapper = styled.div` ` const VideoCard = ({ item, openVideo }) => { + const first_2_tags = item.tags?.slice(0, 2) + const another_tags_number = item.tags.length > 2 ? `+${item.tags.length - 2}` : '' + const converted_date = convertDate(item.published_date) return ( // the extra div surrounding the videocard is to get around Safari's different // interpretation of height: 100% @@ -118,14 +121,14 @@ const VideoCard = ({ item, openVideo }) => { {item.tags && - item.tags.slice(0, 2).map((tag) => ( + first_2_tags.map((tag) => ( {tag.tags_id.tag_name} ))} - {item.tags.length > 2 && ( + {another_tags_number && ( - {`+${item.tags.slice(2).length.toString()}`} + {another_tags_number} )} @@ -146,7 +149,7 @@ const VideoCard = ({ item, openVideo }) => { {item.video_title}
- {convertDate(item.published_date)} + {converted_date}