mirror of
https://github.com/wassname/talk.git
synced 2026-08-17 11:27:52 +08:00
Don't export internals of embed stream in plugin-api (for now)
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
import update from 'immutability-helper';
|
import update from 'immutability-helper';
|
||||||
|
import {insertCommentsSorted} from 'coral-framework/utils';
|
||||||
|
|
||||||
function determineCommentDepth(comment) {
|
function determineCommentDepth(comment) {
|
||||||
let depth = 0;
|
let depth = 0;
|
||||||
let cur = comment;
|
let cur = comment;
|
||||||
@@ -142,27 +144,6 @@ export function findCommentInEmbedQuery(root, callbackOrId) {
|
|||||||
return findComment(root.asset.comments.nodes, callback);
|
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) {
|
function findAndInsertFetchedComments(parent, comments, parent_id) {
|
||||||
const isAsset = parent.__typename === 'Asset';
|
const isAsset = parent.__typename === 'Asset';
|
||||||
const connectionField = isAsset ? 'comments' : 'replies';
|
const connectionField = isAsset ? 'comments' : 'replies';
|
||||||
@@ -175,11 +156,9 @@ function findAndInsertFetchedComments(parent, comments, parent_id) {
|
|||||||
if (isAsset) {
|
if (isAsset) {
|
||||||
return nodes.concat(comments.nodes);
|
return nodes.concat(comments.nodes);
|
||||||
}
|
}
|
||||||
return nodes
|
return insertCommentsSorted(nodes, comments.nodes.filter(
|
||||||
.concat(comments.nodes.filter(
|
|
||||||
(comment) => !nodes.some((node) => node.id === comment.id)
|
(comment) => !nodes.some((node) => node.id === comment.id)
|
||||||
))
|
));
|
||||||
.sort(ascending);
|
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -144,3 +144,25 @@ export function forEachError(error, callback) {
|
|||||||
callback({error: e, msg});
|
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 +0,0 @@
|
|||||||
export {setActiveTab} from 'coral-embed-stream/src/actions/stream';
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export {insertCommentsSorted} from 'coral-framework/utils';
|
||||||
@@ -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 {compose, gql} from 'react-apollo';
|
||||||
import TabPane from '../components/TabPane';
|
import TabPane from '../components/TabPane';
|
||||||
import {withFragments} from 'plugin-api/beta/client/hocs';
|
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) =>
|
const mapDispatchToProps = (dispatch) =>
|
||||||
bindActionCreators({
|
bindActionCreators({
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import FeaturedButton from './components/FeaturedButton';
|
|||||||
import translations from './translations.json';
|
import translations from './translations.json';
|
||||||
import update from 'immutability-helper';
|
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 {
|
export default {
|
||||||
translations,
|
translations,
|
||||||
@@ -51,7 +52,7 @@ export default {
|
|||||||
asset: {
|
asset: {
|
||||||
featuredComments: {
|
featuredComments: {
|
||||||
nodes: {
|
nodes: {
|
||||||
$apply: (nodes) => insertCommentSorted(nodes, comment, 'REVERSE_CHRONOLOGICAL')
|
$apply: (nodes) => insertCommentsSorted(nodes, comment, 'REVERSE_CHRONOLOGICAL')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
featuredCommentsCount: {
|
featuredCommentsCount: {
|
||||||
|
|||||||
Reference in New Issue
Block a user