From 607df2b960b79f67ca37c6666772ec797bb065b4 Mon Sep 17 00:00:00 2001 From: echenley Date: Sun, 1 Nov 2015 16:05:39 -0600 Subject: [PATCH] break up PostInfo into stateless fn components --- src/js/components/Post.jsx | 2 +- src/js/components/PostCommentsLink.jsx | 20 ++++++++++++++ src/js/components/PostCreatorLink.jsx | 16 +++++++++++ src/js/components/PostDeleteLink.jsx | 16 +++++++++++ src/js/components/PostInfo.jsx | 33 ++++++---------------- src/js/components/PostLink.jsx | 3 +- src/js/components/PostTimeAgo.jsx | 16 +++++++++++ src/js/components/Spinner.jsx | 38 ++++++++++++-------------- 8 files changed, 98 insertions(+), 46 deletions(-) create mode 100644 src/js/components/PostCommentsLink.jsx create mode 100644 src/js/components/PostCreatorLink.jsx create mode 100644 src/js/components/PostDeleteLink.jsx create mode 100644 src/js/components/PostTimeAgo.jsx diff --git a/src/js/components/Post.jsx b/src/js/components/Post.jsx index 87c92ad..4acdc7f 100644 --- a/src/js/components/Post.jsx +++ b/src/js/components/Post.jsx @@ -27,7 +27,7 @@ const Post = React.createClass({ return (
- +
); diff --git a/src/js/components/PostCommentsLink.jsx b/src/js/components/PostCommentsLink.jsx new file mode 100644 index 0000000..437870a --- /dev/null +++ b/src/js/components/PostCommentsLink.jsx @@ -0,0 +1,20 @@ +'use strict'; + +import React, { PropTypes } from 'react'; +import Link from 'react-router/lib/Link'; +import pluralize from '../util/pluralize'; + +const CommentsLink = ({ postId, commentCount }) => ( + + + { pluralize(commentCount, 'comment') } + + +); + +CommentsLink.PropTypes = { + postId: PropTypes.string, + commentCount: PropTypes.number +}; + +export default CommentsLink; diff --git a/src/js/components/PostCreatorLink.jsx b/src/js/components/PostCreatorLink.jsx new file mode 100644 index 0000000..7c4f14f --- /dev/null +++ b/src/js/components/PostCreatorLink.jsx @@ -0,0 +1,16 @@ +'use strict'; + +import React, { PropTypes } from 'react'; +import { Link } from 'react-router'; + +const PostCreatorLink = ({ creator }) => ( + + { creator } + +); + +PostCreatorLink.PropTypes = { + creator: PropTypes.string +}; + +export default PostCreatorLink; diff --git a/src/js/components/PostDeleteLink.jsx b/src/js/components/PostDeleteLink.jsx new file mode 100644 index 0000000..c2cfe0b --- /dev/null +++ b/src/js/components/PostDeleteLink.jsx @@ -0,0 +1,16 @@ +'use strict'; + +import { PropTypes } from 'react'; +import Actions from '../actions/Actions'; + +const PostDeleteLink = ({ post }) => ( + + Actions.deletePost(post) }>delete + +); + +PostDeleteLink.PropTypes = { + post: PropTypes.object +}; + +export default PostDeleteLink; diff --git a/src/js/components/PostInfo.jsx b/src/js/components/PostInfo.jsx index da73bb2..e605998 100644 --- a/src/js/components/PostInfo.jsx +++ b/src/js/components/PostInfo.jsx @@ -1,14 +1,14 @@ 'use strict'; import React, { PropTypes } from 'react'; -import { Link } from 'react-router'; import Actions from '../actions/Actions'; import Upvote from './Upvote'; - -import pluralize from '../util/pluralize'; -import timeAgo from '../util/timeAgo'; +import PostCommentsLink from './PostCommentsLink'; +import PostTimeAgo from './PostTimeAgo'; +import PostCreatorLink from './PostCreatorLink'; +import PostDeleteLink from './PostDeleteLink'; const PostLink = React.createClass({ @@ -21,20 +21,13 @@ const PostLink = React.createClass({ const { user, post } = this.props; let userUpvoted = user.upvoted || {}; + let creatorIsLoggedIn = user.uid === post.creatorUID; - let commentCount = post.commentCount || 0; let upvoteActions = { upvote: Actions.upvotePost, downvote: Actions.downvotePost }; - // add delete option if creator is logged in - let deleteOption = user.uid === post.creatorUID && ( - - Actions.deletePost(post) }>delete - - ); - return (
- - { post.creator } - - - { timeAgo(post.time) } - - - - { pluralize(commentCount, 'comment') } - - - { deleteOption } + + + + { creatorIsLoggedIn && }
); } diff --git a/src/js/components/PostLink.jsx b/src/js/components/PostLink.jsx index a9737b0..26faf4a 100644 --- a/src/js/components/PostLink.jsx +++ b/src/js/components/PostLink.jsx @@ -13,7 +13,8 @@ const PostLink = ({ url, title }) => ( ); PostLink.PropTypes = { - post: PropTypes.object + url: PropTypes.string, + title: PropTypes.string }; export default PostLink; diff --git a/src/js/components/PostTimeAgo.jsx b/src/js/components/PostTimeAgo.jsx new file mode 100644 index 0000000..c945c9e --- /dev/null +++ b/src/js/components/PostTimeAgo.jsx @@ -0,0 +1,16 @@ +'use strict'; + +import React, { PropTypes } from 'react'; +import timeAgo from '../util/timeAgo'; + +const PostTimeAgo = ({ time }) => ( + + { timeAgo(time) } + +); + +PostTimeAgo.PropTypes = { + time: PropTypes.string +}; + +export default PostTimeAgo; diff --git a/src/js/components/Spinner.jsx b/src/js/components/Spinner.jsx index c0e9565..22357ac 100644 --- a/src/js/components/Spinner.jsx +++ b/src/js/components/Spinner.jsx @@ -2,28 +2,26 @@ import React from 'react'; -const Spinner = React.createClass({ - render() { - var bars = []; - var barStyle; +const Spinner = (props) => { + let bars = []; + let barStyle; - for (var i = 0; i < 12; i++) { - barStyle = {}; - barStyle.WebkitAnimationDelay = barStyle.animationDelay = - (i - 12) / 10 + 's'; - barStyle.WebkitTransform = barStyle.transform = - 'rotate(' + (i * 30) + 'deg) translate(146%)'; - bars.push( -
- ); - } - - return ( -
- { bars } -
+ for (let i = 0; i < 12; i++) { + barStyle = {}; + barStyle.WebkitAnimationDelay = barStyle.animationDelay = + (i - 12) / 10 + 's'; + barStyle.WebkitTransform = barStyle.transform = + 'rotate(' + (i * 30) + 'deg) translate(146%)'; + bars.push( +
); } -}); + + return ( +
+ { bars } +
+ ); +}; export default Spinner;