Skip to content

Comment count doesn't update in Scream component without refreshing #11

@AndrewYinLi

Description

@AndrewYinLi

@hidjou

Comment count doesn't update in Scream component, only updates in ScreamDialog if you don't refresh the page. This is because in our state we only update commentCount in scream (accessed by ScreamDialog and not also screams (accessed by Scream).

This can be fixed in dataReducer.js by replacing the code for case SUBMIT_COMMENT: with the following:

case SUBMIT_COMMENT:
      let commentedOnIndex = state.screams.findIndex(
        scream => scream.screamId === action.payload.screamId
      );
      return {
        ...state,
        scream: {
          ...state.scream,
          comments: [action.payload, ...state.scream.comments],
          commentCount: state.scream.commentCount + 1
        },
        screams: state.screams.map((scream, screamsArrIndex) =>
          screamsArrIndex === commentedOnIndex
            ? { ...scream, commentCount: scream.commentCount + 1 }
            : scream
        )
      };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions