Replacing 'item_id' with 'id' and removing appendRelatedArray

It now makes sense to have a generic appendItemArray function
This commit is contained in:
David Jay
2016-11-02 15:38:49 -07:00
parent 8020213da5
commit 8f48f62b02
4 changed files with 11 additions and 16 deletions
@@ -8,18 +8,13 @@ const initialState = fromJS({})
export default (state = initialState, action) => {
switch (action.type) {
case actions.ADD_ITEM:
return state.set(action.item_id, fromJS(action.item))
return state.set(action.id, fromJS(action.item))
case actions.UPDATE_ITEM:
return state.updateIn([action.item_id, 'data', action.property], () =>
return state.updateIn([action.id, action.property], () =>
fromJS(action.value)
)
case actions.APPEND_ITEM_ARRAY:
return state.updateIn([action.item_id, 'data', action.property], (prop) => {
return prop ? prop.push(action.value) : fromJS([action.value])
}
)
case actions.APPEND_ITEM_RELATED:
return state.updateIn([action.item_id, 'related', action.property], (prop) => {
return state.updateIn([action.id, action.property], (prop) => {
return prop ? prop.push(action.value) : fromJS([action.value])
}
)
@@ -2,16 +2,16 @@ import React from 'react'
const name = 'coral-plugin-comment-count'
const CommentCount = ({items, item_id}) => {
const CommentCount = ({items, id}) => {
let count = 0
if (items[item_id]) {
count += items[item_id].related.comment.length
if (items[id]) {
count += items[id].comments.length
}
const itemKeys = Object.keys(items)
for (var i=0; i < itemKeys.length; i++) {
const item = items[itemKeys[i]]
if (item.type === 'comment' && item.related && item.related.child) {
count += item.related.child.length
if (item.type === 'comment' && item.children) {
count += item.children.length
}
}
+2 -2
View File
@@ -18,7 +18,7 @@ class CommentBox extends Component {
}
postComment = () => {
const {postItem, updateItem, item_id, reply, addNotification, appendItemRelated} = this.props
const {postItem, updateItem, item_id, reply, addNotification, appendItemArray} = this.props
let comment = {
content: this.state.content
}
@@ -33,7 +33,7 @@ class CommentBox extends Component {
updateItem(item_id, 'showReply', false)
postItem(comment, 'comment')
.then((id) => {
appendItemRelated(item_id, related, id)
appendItemArray(item_id, related, id)
addNotification('success', 'Your comment has been posted.')
}).catch((err) => console.error(err))
this.setState({content: ''})
+1 -1
View File
@@ -11,7 +11,7 @@ const ReplyBox = (props) => <div
item_id = {props.item_id}
postItem = {props.postItem}
addNotification = {props.addNotification}
appendItemRelated = {props.appendItemRelated}
appendItemArray = {props.appendItemArray}
updateItem = {props.updateItem}
comments = {props.child}
reply = {true}/>