-
Notifications
You must be signed in to change notification settings - Fork 59
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(components/atom/videoPlayer): add factory hook #2524
Open
andresin87
wants to merge
2
commits into
master
Choose a base branch
from
video-player
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
26 changes: 11 additions & 15 deletions
26
components/atom/videoPlayer/src/components/VimeoPlayer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import YouTubePlayer from './YouTubePlayer.js' | ||
import VimeoPlayer from './VimeoPlayer.js' | ||
|
||
export {YouTubePlayer, VimeoPlayer} |
15 changes: 0 additions & 15 deletions
15
components/atom/videoPlayer/src/hooks/useDetectVideoType.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {VIMEO, YOUTUBE, BASE_CLASS} from '../settings.js' | ||
import {VimeoPlayer, YouTubePlayer} from '../components/index.js' | ||
|
||
const matcher = (arrayPattern, value) => | ||
arrayPattern.find(pattern => value.includes(pattern)) | ||
|
||
const useVideoPlayer = ({ | ||
as: As = 'div', | ||
children = 'Not supported media type', | ||
className, | ||
src = '', | ||
...props | ||
} = {}) => { | ||
if (matcher([YOUTUBE.VIDEO_TYPE, YOUTUBE.SHORT_URL], src)) { | ||
return [ | ||
YouTubePlayer, | ||
{ | ||
className: [BASE_CLASS, `${BASE_CLASS}-youtubePlayer`].join(' '), | ||
src, | ||
...props | ||
} | ||
] | ||
} else if (matcher([VIMEO.VIDEO_TYPE], src)) { | ||
return [ | ||
VimeoPlayer, | ||
{ | ||
className: [BASE_CLASS, `${BASE_CLASS}-vimeoPlayer`].join(' '), | ||
src, | ||
...props | ||
} | ||
] | ||
} | ||
return ['h1', {className: BASE_CLASS, children, ...props}] | ||
} | ||
export default useVideoPlayer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
import {forwardRef} from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import Switcher from './components/Switcher.js' | ||
import {BASE_CLASS} from './settings.js' | ||
export default function AtomVideoPlayer({src = ''}) { | ||
import useVideoPlayer from './hooks/useVideoPlayer.js' | ||
|
||
const AtomVideoPlayer = forwardRef((props, forwardedRef) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, we totally forgot about forwarding ref. |
||
const [Component, {className, as: As = 'div', ...componentProps}] = | ||
useVideoPlayer(props) | ||
return ( | ||
<div className={BASE_CLASS}> | ||
<Switcher src={src} /> | ||
</div> | ||
<As className={className} ref={forwardedRef}> | ||
<Component {...componentProps} /> | ||
</As> | ||
) | ||
} | ||
}) | ||
|
||
AtomVideoPlayer.displayName = 'AtomVideoPlayer' | ||
AtomVideoPlayer.propTypes = { | ||
/* Render the passed value as the correspondent HTML tag or the component if a function is passed */ | ||
as: PropTypes.elementType, | ||
// TODO: document | ||
src: PropTypes.string | ||
} | ||
|
||
export default AtomVideoPlayer |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your proposal.
I'm wondering if this is an agreement of how to create these kind of structures in Sui.
Probably I'm missing the benefit or architectural pattern behind this change, but IMO this is making the same effect than the already existing code, but in a less obvious way, delegating some representation responsibilities to the
useVideoPlayer
hook.All of this is still entirely my opinion, but without knowing the benefits of applying this alternative approach, it's more difficult in my opinion to read the code and follow the logic flow. For example is less obvious were the
vimeoPlayer
style class is used. In the already existing approach, the Vimeo player component self-contains both all the needed logic and css class references, and the switch mechanism has a very specific and limited responsibility.Maybe we can have a discussion about this when you have a moment for us!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reduces the VDOM tree reconciliation. Take a look on react-dev-tools, there is non
Switcher
component