Add new sorting variables

This commit is contained in:
Chi Vinh Le
2017-08-24 21:30:16 +07:00
parent d1a3a67b35
commit ddb555e07f
6 changed files with 73 additions and 15 deletions
@@ -151,7 +151,15 @@ const slots = [
];
const EMBED_QUERY = gql`
query CoralEmbedStream_Embed($assetId: ID, $assetUrl: String, $commentId: ID!, $hasComment: Boolean!, $excludeIgnored: Boolean) {
query CoralEmbedStream_Embed(
$assetId: ID,
$assetUrl: String,
$commentId: ID!,
$hasComment: Boolean!,
$excludeIgnored: Boolean,
$sortBy: SORT_COMMENTS_BY!,
$sort: SORT_ORDER!,
) {
me {
id
status
@@ -163,13 +171,15 @@ const EMBED_QUERY = gql`
`;
export const withEmbedQuery = withQuery(EMBED_QUERY, {
options: ({auth, commentId, assetId, assetUrl}) => ({
options: ({auth, commentId, assetId, assetUrl, sortBy, sort}) => ({
variables: {
assetId,
assetUrl,
commentId,
hasComment: commentId !== '',
excludeIgnored: Boolean(auth && auth.user && auth.user.id),
sortBy,
sort,
},
}),
});
@@ -180,7 +190,9 @@ const mapStateToProps = (state) => ({
assetId: state.stream.assetId,
assetUrl: state.stream.assetUrl,
activeTab: state.embed.activeTab,
config: state.config
config: state.config,
sort: state.stream.sort,
sortBy: state.stream.sortBy,
});
const mapDispatchToProps = (dispatch) =>
@@ -119,7 +119,8 @@ class StreamContainer extends React.Component {
cursor: this.props.root.asset.comments.endCursor,
parent_id: null,
asset_id: this.props.root.asset.id,
sort: 'DESC',
sort: this.props.data.variables.sort,
sortBy: this.props.data.variables.sortBy,
excludeIgnored: this.props.data.variables.excludeIgnored,
},
updateQuery: (prev, {fetchMoreResult:{comments}}) => {
@@ -203,8 +204,26 @@ const COMMENTS_EDITED_SUBSCRIPTION = gql`
`;
const LOAD_MORE_QUERY = gql`
query CoralEmbedStream_LoadMoreComments($limit: Int = 5, $cursor: Cursor, $parent_id: ID, $asset_id: ID, $sort: SORT_ORDER, $excludeIgnored: Boolean) {
comments(query: {limit: $limit, cursor: $cursor, parent_id: $parent_id, asset_id: $asset_id, sort: $sort, excludeIgnored: $excludeIgnored}) {
query CoralEmbedStream_LoadMoreComments(
$limit: Int = 5
$cursor: Cursor
$parent_id: ID
$asset_id: ID
$sort: SORT_ORDER
$sortBy: SORT_COMMENTS_BY = CREATED_AT
$excludeIgnored: Boolean
) {
comments(
query: {
limit: $limit
cursor: $cursor
parent_id: $parent_id
asset_id: $asset_id
sort: $sort
sortBy: $sortBy
excludeIgnored: $excludeIgnored
}
) {
nodes {
...CoralEmbedStream_Stream_comment
}
@@ -255,7 +274,7 @@ const fragments = {
}
commentCount @skip(if: $hasComment)
totalCommentCount @skip(if: $hasComment)
comments(query: {limit: 10, excludeIgnored: $excludeIgnored}) @skip(if: $hasComment) {
comments(query: {limit: 10, excludeIgnored: $excludeIgnored, sort: $sort, sortBy: $sortBy}) @skip(if: $hasComment) {
nodes {
...CoralEmbedStream_Stream_comment
}
@@ -56,7 +56,7 @@ const extension = {
fragment CoralEmbedStream_CreateCommentResponse on CreateCommentResponse {
comment {
...CoralEmbedStream_CreateCommentResponse_Comment
replies(query: {}) {
replies {
nodes {
...CoralEmbedStream_CreateCommentResponse_Comment
}
@@ -23,6 +23,8 @@ const initialState = {
commentClassNames: [],
activeTab: process.env.TALK_DEFAULT_STREAM_TAB,
previousTab: '',
sortBy: 'CREATED_AT',
sort: 'DESC',
};
export default function stream(state = initialState, action) {