Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions client/state/comments/actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @format */
/**
* Internal dependencies
*/
Expand All @@ -23,7 +24,7 @@ import { NUMBER_OF_COMMENTS_PER_FETCH } from './constants';
export const requestComment = ( { siteId, commentId } ) => ( {
type: COMMENT_REQUEST,
siteId,
commentId
commentId,
} );

/***
Expand All @@ -37,7 +38,7 @@ export function requestPostComments( {
siteId,
postId,
status = 'approved',
direction = 'before'
direction = 'before',
} ) {
if ( ! isEnabled( 'comments/filters-in-posts' ) ) {
status = 'approved';
Expand Down Expand Up @@ -94,7 +95,12 @@ export const requestCommentsTreeForSite = query => ( {
* @param {Boolean} options.showSuccessNotice Announce the delete success with a notice (default: true)
* @returns {Object} action that deletes a comment
*/
export const deleteComment = ( siteId, postId, commentId, options = { showSuccessNotice: true } ) => ( {
export const deleteComment = (
siteId,
postId,
commentId,
options = { showSuccessNotice: true }
) => ( {
type: COMMENTS_DELETE,
siteId,
postId,
Expand Down Expand Up @@ -196,15 +202,15 @@ export function editComment( siteId, postId, commentId, content ) {
postId,
commentId,
content: data.content,
} ),
} )
)
.catch( () =>
dispatch( {
type: COMMENTS_EDIT_FAILURE,
siteId,
postId,
commentId,
} ),
} )
);
};
}
1 change: 1 addition & 0 deletions client/state/comments/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @format */
export const NUMBER_OF_COMMENTS_PER_FETCH = 50;

export const PLACEHOLDER_STATE = {
Expand Down
9 changes: 5 additions & 4 deletions client/state/comments/from-api.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @format */
/**
* External dependencies
*/
Expand All @@ -15,7 +16,7 @@ export const toAuthor = ( { avatar_URL, email, ID, name } ) => {
{ kind: 'anonymous' },
avatar_URL && { avatar: avatar_URL },
email && { email },
name && { displayName: name },
name && { displayName: name }
);
};

Expand All @@ -30,7 +31,7 @@ export const toWpcomUser = author =>
primary_blog_url: author.URL,
username: author.login,
},
a => !! a,
a => !! a
);

export const validStatusValues = {
Expand Down Expand Up @@ -67,10 +68,10 @@ export const fromApi = ( siteId, data ) => {
postId: parseInt( data.post.ID, 10 ),
siteId,
status: validStatusValues[ data.status ],
},
}
),
},
data.author.ID > 0 && { user: toWpcomUser( data.author ) },
data.author.ID > 0 && { user: toWpcomUser( data.author ) }
);
} catch ( e ) {
return {
Expand Down
18 changes: 11 additions & 7 deletions client/state/comments/reducer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @format */
/**
* External dependencies
*/
Expand Down Expand Up @@ -92,15 +93,15 @@ export function items( state = {}, action ) {
...state,
[ stateKey ]: map(
state[ stateKey ],
updateComment( commentId, { i_like: true, like_count } ),
updateComment( commentId, { i_like: true, like_count } )
),
};
case COMMENTS_UNLIKE:
return {
...state,
[ stateKey ]: map(
state[ stateKey ],
updateComment( commentId, { i_like: false, like_count } ),
updateComment( commentId, { i_like: false, like_count } )
),
};
case COMMENTS_ERROR:
Expand All @@ -112,7 +113,7 @@ export function items( state = {}, action ) {
updateComment( commentId, {
placeholderState: PLACEHOLDER_STATE.ERROR,
placeholderError: error,
} ),
} )
),
};
}
Expand Down Expand Up @@ -169,7 +170,7 @@ export const fetchStatus = createReducer(
? state
: { ...state, [ stateKey ]: nextState };
},
},
}
);

/***
Expand All @@ -189,7 +190,7 @@ export const totalCommentsCount = createReducer(
const key = getStateKey( action.siteId, action.postId );
return { ...state, [ key ]: state[ key ] + 1 };
},
},
}
);

/**
Expand All @@ -210,7 +211,7 @@ export const errors = createReducer(
[ key ]: { error: true },
};
},
},
}
);

export const treesInitializedReducer = ( state = {}, action ) => {
Expand All @@ -220,7 +221,10 @@ export const treesInitializedReducer = ( state = {}, action ) => {
return state;
};

export const treesInitialized = keyedReducer( 'siteId', keyedReducer( 'status', treesInitializedReducer ) );
export const treesInitialized = keyedReducer(
'siteId',
keyedReducer( 'status', treesInitializedReducer )
);

export default combineReducers( {
items,
Expand Down
1 change: 1 addition & 0 deletions client/state/comments/selectors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @format */
/***
* External dependencies
*/
Expand Down
1 change: 1 addition & 0 deletions client/state/comments/test/actions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @format */
/**
* External dependencies
*/
Expand Down
45 changes: 20 additions & 25 deletions client/state/comments/test/reducer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @format */
/**
* External dependencies
*/
Expand Down Expand Up @@ -198,50 +199,44 @@ describe( 'reducer', () => {
type: COMMENTS_COUNT_INCREMENT,
siteId: 1,
postId: 1,
},
}
);

expect( response[ '1-1' ] ).to.eql( 2 );
} );
} );
describe( '#treesInitialized()', () => {
it( 'should track when a tree is initialized for a given query', () => {
const state = treesInitialized(
undefined,
{
type: COMMENTS_TREE_SITE_ADD,
siteId: 77203074,
status: 'unapproved',
} );
const state = treesInitialized( undefined, {
type: COMMENTS_TREE_SITE_ADD,
siteId: 77203074,
status: 'unapproved',
} );
expect( state ).to.eql( {
77203074: { unapproved: true }
77203074: { unapproved: true },
} );
} );
it( 'can track init status of many states', () => {
const initState = deepFreeze( { 77203074: { unapproved: true } } );
const state = treesInitialized(
initState,
{
type: COMMENTS_TREE_SITE_ADD,
siteId: 77203074,
status: 'spam',
} );
const state = treesInitialized( initState, {
type: COMMENTS_TREE_SITE_ADD,
siteId: 77203074,
status: 'spam',
} );
expect( state ).to.eql( {
77203074: { unapproved: true, spam: true }
77203074: { unapproved: true, spam: true },
} );
} );
it( 'can track init status of many sites', () => {
const initState = deepFreeze( { 77203074: { unapproved: true } } );
const state = treesInitialized(
initState,
{
type: COMMENTS_TREE_SITE_ADD,
siteId: 2916284,
status: 'unapproved',
} );
const state = treesInitialized( initState, {
type: COMMENTS_TREE_SITE_ADD,
siteId: 2916284,
status: 'unapproved',
} );
expect( state ).to.eql( {
77203074: { unapproved: true },
2916284: { unapproved: true }
2916284: { unapproved: true },
} );
} );
} );
Expand Down
5 changes: 3 additions & 2 deletions client/state/comments/test/selectors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @format */
/**
* External dependencies
*/
Expand Down Expand Up @@ -51,7 +52,7 @@ describe( 'selectors', () => {
comments: { items: { '1-1': [] } },
},
1,
1,
1
);

expect( res ).to.be.eql( undefined );
Expand All @@ -71,7 +72,7 @@ describe( 'selectors', () => {
comments: { items: { '1-1': [] } },
},
1,
1,
1
);

expect( res ).to.be.eql( undefined );
Expand Down
9 changes: 4 additions & 5 deletions client/state/comments/trees/reducer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @format */
/**
* External dependencies
*/
Expand All @@ -14,15 +15,13 @@ import {
} from 'state/action-types';
import { keyedReducer } from 'state/utils';

const convertToTree = comments => map(
reject( comments, ( { ID } ) => ! parseInt( ID, 10 ) ),
comment => ( {
const convertToTree = comments =>
map( reject( comments, ( { ID } ) => ! parseInt( ID, 10 ) ), comment => ( {
commentId: get( comment, 'ID' ),
commentParentId: get( comment, 'parent.ID', 0 ),
postId: get( comment, 'post.ID' ),
status: get( comment, 'status' ),
} )
);
} ) );

const siteTree = ( state = [], action ) => {
switch ( action.type ) {
Expand Down