Skip to content

Commit 36f8086

Browse files
committed
Setting ID DESC order on server, disable reorder on client
1 parent 27e3265 commit 36f8086

File tree

7 files changed

+82
-62
lines changed

7 files changed

+82
-62
lines changed

app/controllers/comments_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class CommentsController < ApplicationController
44
# GET /comments
55
# GET /comments.json
66
def index
7-
@comments = Comment.all
7+
@comments = Comment.all.order("id DESC")
88
end
99

1010
# GET /comments/1

app/controllers/pages_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ def simple
3232
private
3333

3434
def set_comments
35-
@comments = Comment.all
35+
@comments = Comment.all.order("id DESC")
3636
end
3737
end

client/app/bundles/comments/components/CommentBox/CommentList/CommentList.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class CommentList extends BaseComponent {
3333

3434
render() {
3535
const { $$comments, cssTransitionGroupClassNames } = this.props;
36-
const commentNodes = $$comments.reverse().map($$comment => {
36+
const commentNodes = $$comments.map($$comment => {
3737
// `key` is a React-specific concept and is not mandatory for the
3838
// purpose of this tutorial. if you're curious, see more here:
3939
// http://facebook.github.io/react/docs/multiple-components.html#dynamic-children

client/app/bundles/comments/components/CommentBox/CommentList/CommentList.spec.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('CommentList', () => {
3131
}),
3232
);
3333

34-
it('renders a list of Comments in reverse order', () => {
34+
it('renders a list of Comments in normal order', () => {
3535
const component = renderIntoDocument(
3636
<CommentList
3737
$$comments={comments}
@@ -40,8 +40,8 @@ describe('CommentList', () => {
4040
);
4141
const list = scryRenderedComponentsWithType(component, Comment);
4242
expect(list.length).to.equal(2);
43-
expect(list[0].props.author).to.equal('Furter');
44-
expect(list[1].props.author).to.equal('Frank');
43+
expect(list[0].props.author).to.equal('Frank');
44+
expect(list[1].props.author).to.equal('Furter');
4545
});
4646

4747
it('renders an alert if errors', () => {

client/app/bundles/comments/components/SimpleCommentScreen/SimpleCommentScreen.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default class SimpleCommentScreen extends BaseComponent {
5353
const $$comment = Immutable.fromJS(comment);
5454

5555
this.setState({
56-
$$comments: $$comments.push($$comment),
56+
$$comments: $$comments.unshift($$comment),
5757
isSaving: false,
5858
});
5959
})

client/app/bundles/comments/reducers/commentsReducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function commentsReducer($$state = $$initialState, action = null)
3737
state
3838
.updateIn(
3939
['$$comments'],
40-
$$comments => $$comments.push(Immutable.fromJS(comment))
40+
$$comments => $$comments.unshift(Immutable.fromJS(comment))
4141
)
4242
.merge({
4343
submitCommentError: null,

client/npm-shrinkwrap.json

Lines changed: 74 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)