Fix load more buttons

This commit is contained in:
Chi Vinh Le
2017-04-13 01:17:46 +07:00
parent c19e2979fc
commit 92205a2c6f
5 changed files with 24 additions and 5 deletions
+9 -3
View File
@@ -79,10 +79,12 @@ class Embed extends Component {
if(!isEqual(nextProps.data.asset, this.props.data.asset)) {
loadAsset(nextProps.data.asset);
const {getCounts, updateCountCache} = this.props;
const {getCounts, updateCountCache, asset: {countCache}} = this.props;
const {asset} = nextProps.data;
updateCountCache(asset.id, asset.commentCount);
if (!countCache) {
updateCountCache(asset.id, asset.commentCount);
}
this.setState({
countPoll: setInterval(() => {
@@ -127,6 +129,10 @@ class Embed extends Component {
const banned = user && user.status === 'BANNED';
const hasOlderComments =
asset && asset.lastComment &&
asset.lastComment.id !== asset.comments[asset.comments.length - 1].id;
const expandForLogin = showSignInDialog ? {
minHeight: document.body.scrollHeight + 200
} : {};
@@ -259,7 +265,7 @@ class Embed extends Component {
topLevel={true}
assetId={asset.id}
comments={asset.comments}
moreComments={countCache[asset.id] > asset.comments.length}
moreComments={hasOlderComments}
loadMore={this.props.loadMore} />
</div>
}
+2 -2
View File
@@ -17,10 +17,10 @@ const onLoadMoreClick = ({loadMore, commentCount, firstCommentDate, assetId, upd
const NewCount = (props) => {
const newComments = props.commentCount - props.countCache;
return <div className='coral-new-comments'>
return <div className='coral-new-comments coral-load-more'>
{
props.countCache && newComments > 0 ?
<button onClick={onLoadMoreClick(props)} className='coral-load-more'>
<button onClick={onLoadMoreClick(props)}>
{newComments === 1
? lang.t('newCount', newComments, lang.t('comment'))
: lang.t('newCount', newComments, lang.t('comments'))}
@@ -38,6 +38,9 @@ query AssetQuery($asset_id: ID, $asset_url: String, $comment_id: ID!, $has_comme
}
commentCount
totalCommentCount
lastComment {
id
}
comments(limit: 10) {
...commentView
replyCount
+7
View File
@@ -1,4 +1,11 @@
const Asset = {
lastComment({id}, _, {loaders: {Comments}}) {
return Comments.getByQuery({
asset_id: id,
limit: 1,
parent_id: null
}).then(data => data[0]);
},
recentComments({id}, _, {loaders: {Comments}}) {
return Comments.genRecentComments.load(id);
},
+3
View File
@@ -413,6 +413,9 @@ type Asset {
# The URL that the asset is located on.
url: String
# Returns last comment
lastComment: Comment
# Returns recent comments
recentComments: [Comment]