🚧 Add Loaders to all template-using pages
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / BookmarksPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.main.*
5 import net.pterodactylus.sone.utils.paginate
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.*
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
10 import javax.inject.Inject
11
12 /**
13  * Page that lets the user browse all his bookmarked posts.
14  */
15 @MenuName("Bookmarks")
16 class BookmarksPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) :
17                 SoneTemplatePage("bookmarks.html", webInterface, loaders, template = template, pageTitleKey = "Page.Bookmarks.Title") {
18
19         override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
20                 soneRequest.core.bookmarkedPosts.let { posts ->
21                         val pagination = posts.filter(Post::isLoaded).sortedByDescending { it.time }.paginate(soneRequest.core.preferences.postsPerPage)
22                         templateContext["pagination"] = pagination
23                         templateContext["posts"] = pagination.items
24                         templateContext["postsNotLoaded"] = posts.any { !it.isLoaded }
25                 }
26         }
27
28 }