Skip to content
This repository
Browse code

new stream now remembers how far you have scrolled.

also, jasmine is really cool.
  • Loading branch information...
commit 82218fd7cba89c9b2eda06f70660d804d32d2ab5 1 parent 92c0fa0
Maxwell Salzberg authored
15  app/assets/javascripts/app/pages/stream.js
@@ -29,5 +29,18 @@ app.pages.Stream = app.views.Base.extend({
29 29
 
30 30
   postRenderTemplate : function() {
31 31
     this.$("#header").css("background-image", "url(" + app.currentUser.get("wallpaper") + ")")
32  
-  }
  32
+    this.setUpHashChangeOnStreamLoad()
  33
+  },
  34
+
  35
+  setUpHashChangeOnStreamLoad : function(){
  36
+    var self = this;
  37
+    this.streamView.on('loadMore', function(){
  38
+      var post = this.stream.items.last();
  39
+      self.navigateToPost(post)
  40
+    });
  41
+  },
  42
+
  43
+  navigateToPost : function(post){
  44
+    app.router.navigate(location.pathname + "?ex=true&max_time=" + post.createdAt(), {replace: true})
  45
+  },
33 46
 });
1  app/assets/javascripts/app/router.js
... ...
@@ -1,6 +1,7 @@
1 1
 app.Router = Backbone.Router.extend({
2 2
   routes: {
3 3
     //new hotness
  4
+    "stream?ex=true:params": 'newStream',
4 5
     "stream?ex=true": 'newStream',
5 6
     "people/:id?ex=true": "newProfile",
6 7
     "posts/new" : "composer",
20  spec/javascripts/app/pages/stream_spec.js
@@ -10,7 +10,6 @@ describe("app.Pages.Stream", function(){
10 10
   describe('postRenderTemplate', function(){
11 11
     it("sets the background-image of #header", function(){
12 12
       this.page.render()
13  
-      console.log(this.page.$('#header').css('background-image'))
14 13
       expect(this.page.$('#header').css('background-image')).toBeTruthy()
15 14
     })
16 15
 
@@ -34,4 +33,23 @@ describe("app.Pages.Stream", function(){
34 33
       })
35 34
     })
36 35
   })
  36
+
  37
+  describe("setUpHashChangeOnStreamLoad", function(){
  38
+    it('calls navigateToPost on the loadMore event', function(){
  39
+      spyOn(this.page, 'navigateToPost')
  40
+      this.page.setUpHashChangeOnStreamLoad()
  41
+      this.page.streamView.trigger('loadMore')
  42
+      expect(this.page.navigateToPost).toHaveBeenCalled()
  43
+    })
  44
+  })
  45
+
  46
+  describe("navigateToPost", function(){
  47
+    it("sets the max time of the url to the created at time of a post", function(){
  48
+      spyOn(app.router, 'navigate')
  49
+      this.page.navigateToPost(this.post)
  50
+      var url = location.pathname + "?ex=true&max_time=" + this.post.createdAt()
  51
+      var options =  {replace: true}
  52
+      expect(app.router.navigate).toHaveBeenCalledWith(url, options)
  53
+    })
  54
+  })
37 55
 });

0 notes on commit 82218fd

Please sign in to comment.
Something went wrong with that request. Please try again.