Clean up some imports
[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.utils.Pagination
5 import net.pterodactylus.sone.web.WebInterface
6 import net.pterodactylus.sone.web.page.FreenetRequest
7 import net.pterodactylus.util.template.Template
8 import net.pterodactylus.util.template.TemplateContext
9
10 /**
11  * Page that lets the user browse all his bookmarked posts.
12  */
13 class BookmarksPage(template: Template, webInterface: WebInterface): SoneTemplatePage("bookmarks.html", template, "Page.Bookmarks.Title", webInterface) {
14
15         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
16                 webInterface.core.bookmarkedPosts.let { posts ->
17                         val pagination = Pagination<Post>(posts.filter { it.isLoaded }.sortedByDescending { it.time }, webInterface.core.preferences.postsPerPage)
18                         templateContext["pagination"] = pagination
19                         templateContext["posts"] = pagination.items
20                         templateContext["postsNotLoaded"] = posts.any { !it.isLoaded }
21                 }
22         }
23
24 }