Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify comments list behavior so API requests are consistent with other types of records. #647

Merged
merged 2 commits into from
Oct 27, 2016

Conversation

begedin
Copy link
Contributor

@begedin begedin commented Oct 26, 2016

What's in this PR?

This makes it so that, on the project.tasks.task route, instead of explicitly fetching comments for the task, we instead simply bind to task.comments instead.

This change causes the following

  • Comments no longer need to be fetched via projects/:id/tasks/:number/comments/ route. Instead, we simply fetch from /comments/ using coalesced id requests.
  • We no longer need the comments adapter at all
  • The model and setupController hooks for the project.tasks.task route are much simpler.

Further options

We could potentially further simplify things.

The setupController hook could check if the session is authenticated and simply push a new comment into the task.comments collection.

The comment-list-component could then be the one that displays either a comment-item component, or some sort of comment-item-edit component, which can be used both for new and existing comments, depending on an isEditing flag.

I believe it would reduce and dry up the code related to this section of the app a good deal, but it can be done in a separate PR. @joshsmith I can create an issue if you think it makes sense to do so. The behavior would be similar to what we're doing with donation goals.

References

Fixes #644

Progress on: code-corps/code-corps-api#372

@joshsmith
Copy link
Contributor

@begedin sure, create an issue, but make it low priority.

Copy link
Contributor

@sbatson5 sbatson5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

setupController(controller, task) {
let user = this.get('currentUser.user');
let newComment = this.store.createRecord('comment', { user });
return controller.setProperties({ newComment, task });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the return here isn't necessary. setupController does not return a value by default:
http://emberjs.com/api/classes/Ember.Route.html#method_setupController

It should be fine to just do controller.setProperties({ newComment, task }); without the return

controller.set('newComment', models.comment);
controller.set('comments', models.comments);
setupController(controller, task) {
let user = this.get('currentUser.user');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of the scope of this PR, but I never like fetching properties directly from Services. It would be nice to have a getUser method:
this.get('currentUser').getUser();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbatson5 so we don't lose this, would you want to open an issue here or do a quick PR for this?

@joshsmith joshsmith merged commit 74ff998 into develop Oct 27, 2016
@joshsmith joshsmith deleted the 644-simplify-comments branch October 27, 2016 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants