discourse/app/models/user_bookmark_list.rb
Martin Brennan c07dd0d22a
FEATURE: Add lazy loading to user bookmarks list (#9317)
This is so users with huge amount of bookmarks do not have to wait a long time to see results.

* Add a bookmark list and list serializer to server-side to be able to handle paging and load more URL
* Use load-more component to load more bookmark items, 20 at a time in user activity
* Change the way current user is loaded for bookmark ember models because it was breaking/losing resolvedTimezone when loading more items
2020-04-01 14:09:07 +10:00

27 lines
532 B
Ruby

# frozen_string_literal: true
class UserBookmarkList
include ActiveModel::Serialization
PER_PAGE = 20
attr_reader :bookmarks
attr_accessor :more_bookmarks_url
def initialize(user: user, guardian: guardian, params: params)
@user = user
@guardian = guardian
@params = params.merge(per_page: PER_PAGE)
@bookmarks = []
end
def load
@bookmarks = BookmarkQuery.new(user: @user, guardian: @guardian, params: @params).list_all
@bookmarks
end
def per_page
@per_page ||= PER_PAGE
end
end