From 17ab4d4941e9781045156969484541061cea07d9 Mon Sep 17 00:00:00 2001 From: andresin87 Date: Mon, 24 Apr 2023 18:43:07 +0200 Subject: [PATCH 1/2] feat(components/atom/videoPlayer): add factory hook --- .../videoPlayer/src/components/Switcher.js | 27 -------------- .../videoPlayer/src/components/VimeoPlayer.js | 10 +++--- .../src/components/YouTubePlayer.js | 22 +++++++----- .../atom/videoPlayer/src/components/index.js | 4 +++ .../src/hooks/useDetectVideoType.js | 15 -------- .../videoPlayer/src/hooks/useVideoPlayer.js | 35 +++++++++++++++++++ components/atom/videoPlayer/src/index.js | 21 ++++++----- 7 files changed, 70 insertions(+), 64 deletions(-) delete mode 100644 components/atom/videoPlayer/src/components/Switcher.js create mode 100644 components/atom/videoPlayer/src/components/index.js delete mode 100644 components/atom/videoPlayer/src/hooks/useDetectVideoType.js create mode 100644 components/atom/videoPlayer/src/hooks/useVideoPlayer.js diff --git a/components/atom/videoPlayer/src/components/Switcher.js b/components/atom/videoPlayer/src/components/Switcher.js deleted file mode 100644 index 9fd486a7c..000000000 --- a/components/atom/videoPlayer/src/components/Switcher.js +++ /dev/null @@ -1,27 +0,0 @@ -import PropTypes from 'prop-types' - -import useDetectVideoType from '../hooks/useDetectVideoType.js' -import {VIMEO, YOUTUBE} from '../settings.js' -import VimeoPlayer from './VimeoPlayer.js' -import YouTubePlayer from './YouTubePlayer.js' - -const Switcher = ({src}) => { - const {detectVideoType} = useDetectVideoType() - const videoType = detectVideoType(src) - switch (videoType) { - case VIMEO.VIDEO_TYPE: - return - - case YOUTUBE.VIDEO_TYPE: - return - - default: - return

Not supported media type

- } -} - -Switcher.propTypes = { - src: PropTypes.string -} - -export default Switcher diff --git a/components/atom/videoPlayer/src/components/VimeoPlayer.js b/components/atom/videoPlayer/src/components/VimeoPlayer.js index e882b972f..8e520bd31 100644 --- a/components/atom/videoPlayer/src/components/VimeoPlayer.js +++ b/components/atom/videoPlayer/src/components/VimeoPlayer.js @@ -1,15 +1,16 @@ +import {forwardRef} from 'react' import PropTypes from 'prop-types' import useVimeoProperties from '../hooks/useVimeoProperties.js' import {BASE_CLASS} from '../settings.js' -const VimeoPlayer = ({src}) => { +const VimeoPlayer = forwardRef(({className, src}, forwardedRef) => { const {getEmbeddableUrl} = useVimeoProperties() const videoSrc = getEmbeddableUrl(src) return ( <> -
+
+ />
{/* Is this really needed? */} {/* */} ) -} +}) VimeoPlayer.propTypes = { + className: PropTypes.string, src: PropTypes.string } diff --git a/components/atom/videoPlayer/src/components/YouTubePlayer.js b/components/atom/videoPlayer/src/components/YouTubePlayer.js index ee4d9bea0..baafde133 100644 --- a/components/atom/videoPlayer/src/components/YouTubePlayer.js +++ b/components/atom/videoPlayer/src/components/YouTubePlayer.js @@ -1,24 +1,28 @@ +import {forwardRef} from 'react' import PropTypes from 'prop-types' import useYouTubeProperties from '../hooks/useYouTubeProperties.js' -const YouTubePlayer = ({src}) => { +const YouTubePlayer = forwardRef(({src, className}, forwardedRef) => { const {getEmbeddableUrl} = useYouTubeProperties() const videoSrc = getEmbeddableUrl(src) // TODO: How to render the iframe with 100% width and height 👉🏾 https://www.h3xed.com/web-development/how-to-make-a-responsive-100-width-youtube-iframe-embed return ( - +
+