1
0

ContentFeed.coffee 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. class ContentFeed extends Class
  2. constructor: ->
  3. @post_create = new PostCreate()
  4. @post_list = new PostList()
  5. @activity_list = new ActivityList()
  6. @new_user_list = new UserList("new")
  7. @suggested_user_list = new UserList("suggested")
  8. @need_update = true
  9. @type = "followed"
  10. @update()
  11. handleListTypeClick: (e) =>
  12. @type = e.currentTarget.attributes.type.value
  13. @post_list.limit = 10
  14. @activity_list.limit = 10
  15. @update()
  16. return false
  17. render: =>
  18. if @post_list.loaded and not Page.on_loaded.resolved then Page.on_loaded.resolve()
  19. if @need_update
  20. @log "Updating", @type
  21. @need_update = false
  22. @new_user_list.need_update = true
  23. @suggested_user_list.need_update = true
  24. # Post list
  25. if @type == "followed"
  26. @post_list.directories = ("data/users/#{key.split('/')[1]}" for key, followed of Page.user.followed_users)
  27. if Page.user.hub # Also show my posts
  28. @post_list.directories.push("data/users/"+Page.user.auth_address)
  29. @post_list.filter_post_ids = null
  30. else if @type == "liked"
  31. @post_list.directories = ("data/users/#{like.split('_')[0]}" for like, _ of Page.user.likes)
  32. @post_list.filter_post_ids = (like.split('_')[1] for like, _ of Page.user.likes)
  33. else
  34. @post_list.directories = "all"
  35. @post_list.filter_post_ids = null
  36. @post_list.need_update = true
  37. # Activity list
  38. if @type == "followed"
  39. @activity_list.directories = ("data/users/#{key.split('/')[1]}" for key, followed of Page.user.followed_users)
  40. else
  41. @activity_list.directories = "all"
  42. @activity_list.update()
  43. h("div#Content.center", [
  44. h("div.col-center", [
  45. @post_create.render(),
  46. h("div.post-list-type",
  47. h("a.link", {href: "#Everyone", onclick: @handleListTypeClick, type: "everyone", classes: {active: @type == "everyone"}}, "Everyone")
  48. h("a.link", {href: "#Liked", onclick: @handleListTypeClick, type: "liked", classes: {active: @type == "liked"}}, "Liked")
  49. h("a.link", {href: "#Followed+users", onclick: @handleListTypeClick, type: "followed", classes: {active: @type == "followed"}}, "Followed users")
  50. ),
  51. @post_list.render()
  52. ]),
  53. h("div.col-right.noscrollfix", [
  54. @activity_list.render(),
  55. if @new_user_list.users.length > 0
  56. h("h2.sep.new", [
  57. "New users",
  58. h("a.link", {href: "?Users", onclick: Page.handleLinkClick}, "Browse all \u203A")
  59. ])
  60. @new_user_list.render(".gray"),
  61. if @suggested_user_list.users.length > 0
  62. h("h2.sep.suggested", [
  63. "Suggested users"
  64. ])
  65. @suggested_user_list.render(".gray"),
  66. ])
  67. ])
  68. update: =>
  69. @need_update = true
  70. Page.projector.scheduleRender()
  71. window.ContentFeed = ContentFeed