Created
October 11, 2015 14:26
-
-
Save ayrton/c20aed8693f990b89479 to your computer and use it in GitHub Desktop.
Stateless React component
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
import PureRenderMixin from 'react-addons-pure-render-mixin'; | |
import React from 'react'; | |
import Audio from './Audio'; | |
import Image from './Image'; | |
import MediaRecord from 'ph/records/MediaRecord'; | |
import PostRecord from 'ph/records/PostRecord'; | |
import Video from './Video'; | |
import {MEDIA_TYPE_AUDIO, MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO} from 'ph/constants/MediaConstants'; | |
/** | |
* Different post thumbnail types. | |
*/ | |
const TYPES = { | |
[MEDIA_TYPE_AUDIO]: Audio, | |
[MEDIA_TYPE_IMAGE]: Image, | |
[MEDIA_TYPE_VIDEO]: Video, | |
}; | |
/** | |
* PostThumbnail component. | |
* | |
* @function | |
* @public | |
*/ | |
const PostThumbnail = ({post}) => { | |
if (!post.thumbnail) { | |
return <span />; | |
} | |
const media = new MediaRecord(post.thumbnail); | |
const Component = TYPES[media.media_type] || Image; | |
return ( | |
<Component media={media} post={post} /> | |
); | |
}; | |
PostThumbnail.mixins = [ | |
PureRenderMixin, | |
]; | |
PostThumbnail.propTypes = { | |
post: React.PropTypes.instanceOf(PostRecord).isRequired, | |
}; | |
export default PostThumbnail; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment