Don't export internals of embed stream in plugin-api (for now)

This commit is contained in:
Chi Vinh Le
2017-07-18 21:04:30 +07:00
parent 19929c97d8
commit 6652368221
7 changed files with 31 additions and 30 deletions
+4 -25
View File
@@ -1,4 +1,6 @@
import update from 'immutability-helper';
import {insertCommentsSorted} from 'coral-framework/utils';
function determineCommentDepth(comment) {
let depth = 0;
let cur = comment;
@@ -142,27 +144,6 @@ export function findCommentInEmbedQuery(root, callbackOrId) {
return findComment(root.asset.comments.nodes, callback);
}
const ascending = (a, b) => {
const dateA = new Date(a.created_at);
const dateB = new Date(b.created_at);
if (dateA < dateB) { return -1; }
if (dateA > dateB) { return 1; }
return 0;
};
const descending = (a, b) => ascending(a, b) * -1;
export function insertCommentSorted(nodes, comment, sortOrder = 'CHRONOLOGICAL') {
const added = nodes.concat(comment);
if (sortOrder === 'CHRONOLOGICAL') {
return added.sort(ascending);
}
if (sortOrder === 'REVERSE_CHRONOLOGICAL') {
return added.sort(descending);
}
throw new Error(`Unknown sort order ${sortOrder}`);
}
function findAndInsertFetchedComments(parent, comments, parent_id) {
const isAsset = parent.__typename === 'Asset';
const connectionField = isAsset ? 'comments' : 'replies';
@@ -175,11 +156,9 @@ function findAndInsertFetchedComments(parent, comments, parent_id) {
if (isAsset) {
return nodes.concat(comments.nodes);
}
return nodes
.concat(comments.nodes.filter(
return insertCommentsSorted(nodes, comments.nodes.filter(
(comment) => !nodes.some((node) => node.id === comment.id)
))
.sort(ascending);
));
}},
},
});
+22
View File
@@ -144,3 +144,25 @@ export function forEachError(error, callback) {
callback({error: e, msg});
});
}
const ascending = (a, b) => {
const dateA = new Date(a.created_at);
const dateB = new Date(b.created_at);
if (dateA < dateB) { return -1; }
if (dateA > dateB) { return 1; }
return 0;
};
const descending = (a, b) => ascending(a, b) * -1;
export function insertCommentsSorted(nodes, comments, sortOrder = 'CHRONOLOGICAL') {
const added = nodes.concat(comments);
if (sortOrder === 'CHRONOLOGICAL') {
return added.sort(ascending);
}
if (sortOrder === 'REVERSE_CHRONOLOGICAL') {
return added.sort(descending);
}
throw new Error(`Unknown sort order ${sortOrder}`);
}
-1
View File
@@ -1 +0,0 @@
export {setActiveTab} from 'coral-embed-stream/src/actions/stream';
+1
View File
@@ -0,0 +1 @@
export {insertCommentsSorted} from 'coral-framework/utils';
-1
View File
@@ -1 +0,0 @@
export {findCommentInEmbedQuery, insertSorted} from 'coral-embed-stream/src/graphql/utils';
@@ -3,7 +3,7 @@ import {bindActionCreators} from 'redux';
import {compose, gql} from 'react-apollo';
import TabPane from '../components/TabPane';
import {withFragments} from 'plugin-api/beta/client/hocs';
import {setActiveTab} from 'plugin-api/beta/client/actions/stream';
import {setActiveTab} from 'coral-embed-stream/src/actions/stream';
const mapDispatchToProps = (dispatch) =>
bindActionCreators({
@@ -5,7 +5,8 @@ import FeaturedButton from './components/FeaturedButton';
import translations from './translations.json';
import update from 'immutability-helper';
import {findCommentInEmbedQuery, insertCommentSorted} from 'plugin-api/beta/client/utils/stream';
import {findCommentInEmbedQuery} from 'coral-embed-stream/src/graphql/utils';
import {insertCommentsSorted} from 'plugin-api/beta/client/utils';
export default {
translations,
@@ -51,7 +52,7 @@ export default {
asset: {
featuredComments: {
nodes: {
$apply: (nodes) => insertCommentSorted(nodes, comment, 'REVERSE_CHRONOLOGICAL')
$apply: (nodes) => insertCommentsSorted(nodes, comment, 'REVERSE_CHRONOLOGICAL')
}
},
featuredCommentsCount: {