Commit 9da7a337 by Matthew Mongeau

Sorting should keep trace of comment and like updates.

parent 2380e7ff
...@@ -439,6 +439,9 @@ if Backbone? ...@@ -439,6 +439,9 @@ if Backbone?
@set('thread', @) @set('thread', @)
super() super()
comment: ->
@set("comments_count", parseInt(@get("comments_count")) + 1)
follow: -> follow: ->
@set('subscribed', true) @set('subscribed', true)
@trigger "thread:follow" @trigger "thread:follow"
......
...@@ -10,6 +10,11 @@ class @DiscussionThreadListView extends Backbone.View ...@@ -10,6 +10,11 @@ class @DiscussionThreadListView extends Backbone.View
initialize: -> initialize: ->
@displayedCollection = new Discussion(@collection.models) @displayedCollection = new Discussion(@collection.models)
@collection.on "change", @reloadDisplayedCollection
reloadDisplayedCollection: =>
@displayedCollection.reset(@collection.models)
# Because we want the behavior that when the body is clicked the menu is # Because we want the behavior that when the body is clicked the menu is
# closed, we need to ignore clicks in the search field and stop propagation. # closed, we need to ignore clicks in the search field and stop propagation.
...@@ -96,10 +101,6 @@ class @DiscussionThreadListView extends Backbone.View ...@@ -96,10 +101,6 @@ class @DiscussionThreadListView extends Backbone.View
@displayedCollection.comparator = @displayedCollection.sortByComments @displayedCollection.comparator = @displayedCollection.sortByComments
@displayedCollection.sort() @displayedCollection.sort()
delay: (callback, ms) =>
clearTimeout(@timer)
@timer = setTimeout(callback, ms)
performSearch: (event) -> performSearch: (event) ->
if event.which == 13 if event.which == 13
event.preventDefault() event.preventDefault()
......
...@@ -62,7 +62,7 @@ class @DiscussionThreadView extends DiscussionContentView ...@@ -62,7 +62,7 @@ class @DiscussionThreadView extends DiscussionContentView
@$(".responses").append(view.el) @$(".responses").append(view.el)
addComment: => addComment: =>
@model.trigger "comment:add" @model.comment()
toggleVote: (event) -> toggleVote: (event) ->
event.preventDefault() event.preventDefault()
......
class @ThreadListItemView extends Backbone.View class @ThreadListItemView extends Backbone.View
tagName: "li" tagName: "li"
template: _.template($("#thread-list-item-template").html()) template: _.template($("#thread-list-item-template").html())
events: events:
"click a": "threadSelected" "click a": "threadSelected"
initialize: -> initialize: ->
@model.on "change", @render @model.on "change", @render
@model.on "thread:follow", @follow @model.on "thread:follow", @follow
@model.on "thread:unfollow", @unfollow @model.on "thread:unfollow", @unfollow
@model.on "comment:add", @addComment
render: => render: =>
@$el.html(@template(@model.toJSON())) @$el.html(@template(@model.toJSON()))
if window.user.following(@model) if window.user.following(@model)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment