Skip to content

Instantly share code, notes, and snippets.

@ayrton
Created October 11, 2015 14:26
Show Gist options
  • Save ayrton/c20aed8693f990b89479 to your computer and use it in GitHub Desktop.
Save ayrton/c20aed8693f990b89479 to your computer and use it in GitHub Desktop.
Stateless React component
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