Add new-users page
authorTheSaminator <TheSaminator@users.noreply.github.com>
Sat, 12 Feb 2022 14:52:46 +0000 (09:52 -0500)
committerTheSaminator <TheSaminator@users.noreply.github.com>
Sat, 12 Feb 2022 14:52:46 +0000 (09:52 -0500)
src/jvmMain/kotlin/starshipfights/data/auth/user_sessions.kt
src/jvmMain/kotlin/starshipfights/data/data_documents.kt
src/jvmMain/kotlin/starshipfights/info/endpoints_info.kt
src/jvmMain/kotlin/starshipfights/info/view_nav.kt
src/jvmMain/kotlin/starshipfights/info/views_main.kt

index 467f0d6876ea2c82c3054810ad0278c6bf1c387c..7fdeed55850db2764ee21f1bf348fbfadefffbdf 100644 (file)
@@ -35,6 +35,7 @@ data class User(
        
        companion object Table : DocumentTable<User> by DocumentTable.create({
                unique(User::discordId)
+               index(User::registeredAt)
        })
 }
 
index f1631c448a2ab0440ad0baa0652ba14428166732..dd5cbc6a61c429b61506cbf3470e1e9b5586e302 100644 (file)
@@ -45,8 +45,9 @@ interface DocumentTable<T : DataDocument<T>> {
        suspend fun del(id: Id<T>)
        suspend fun all(): Flow<T>
        
-       suspend fun select(bson: Bson): Flow<T>
-       suspend fun locate(bson: Bson): T?
+       suspend fun select(where: Bson): Flow<T>
+       suspend fun sorted(order: Bson): Flow<T>
+       suspend fun locate(where: Bson): T?
        suspend fun update(where: Bson, set: Bson)
        suspend fun remove(where: Bson)
        
@@ -105,12 +106,16 @@ private class DocumentTableImpl<T : DataDocument<T>>(val kclass: KClass<T>, priv
                return collection().find().toFlow()
        }
        
-       override suspend fun select(bson: Bson): Flow<T> {
-               return collection().find(bson).toFlow()
+       override suspend fun select(where: Bson): Flow<T> {
+               return collection().find(where).toFlow()
        }
        
-       override suspend fun locate(bson: Bson): T? {
-               return collection().findOne(bson)
+       override suspend fun sorted(order: Bson): Flow<T> {
+               return collection().find().sort(order).toFlow()
+       }
+       
+       override suspend fun locate(where: Bson): T? {
+               return collection().findOne(where)
        }
        
        override suspend fun update(where: Bson, set: Bson) {
index 55ea72ced8aa8083e47f709e1a272ba5d7cbecaa..46ad0948f51c3c2c6f15250ae0f8e8566d1ef08d 100644 (file)
@@ -28,6 +28,10 @@ fun Routing.installPages() {
                call.respondHtml(HttpStatusCode.OK, call.aboutPage())
        }
        
+       get("/users") {
+               call.respondHtml(HttpStatusCode.OK, call.newUsersPage())
+       }
+       
        // Random name generation
        get("/generate-name/{flavor}/{gender}") {
                val flavor = call.parameters["flavor"]?.let { flavor -> AdmiralNameFlavor.values().singleOrNull { it.toUrlSlug() == flavor.lowercase() } }!!
index 77b9717f5ba9747dd8c2b397f323ed62b453ae02..7cf3f67d8067a3546947165db3829132e8e24b96 100644 (file)
@@ -33,6 +33,7 @@ suspend fun ApplicationCall.standardNavBar(): List<NavItem> = listOf(
        NavLink("/", "Main Page"),
        NavLink("/info", "Read Manual"),
        NavLink("/about", "About Starship Fights"),
+       NavLink("/users", "New Users"),
        NavHead("Your Account"),
 ) + when (val user = getUser()) {
        null -> listOf(
index e58b0d1820720c3431f149018397b0a903c850db..fcb89f5c374e201ba83e656630dea3e728fed2b1 100644 (file)
@@ -1,7 +1,11 @@
 package starshipfights.info
 
 import io.ktor.application.*
+import kotlinx.coroutines.flow.take
+import kotlinx.coroutines.flow.toList
 import kotlinx.html.*
+import org.litote.kmongo.descending
+import starshipfights.data.auth.User
 
 suspend fun ApplicationCall.mainPage(): HTML.() -> Unit {
        return page(null, standardNavBar(), IndexSidebar) {
@@ -35,3 +39,28 @@ suspend fun ApplicationCall.aboutPage(): HTML.() -> Unit = page("About", standar
                }
        }
 }
+
+suspend fun ApplicationCall.newUsersPage(): HTML.() -> Unit {
+       val newUsers = User.sorted(descending(User::registeredAt)).take(20).toList()
+       
+       return page("New Users", standardNavBar(), IndexSidebar) {
+               section {
+                       h1 { +"New Users" }
+               }
+               div {
+                       style = "text-align:center"
+                       newUsers.forEach { newUser ->
+                               div {
+                                       style = "display:inline-block;width:24%"
+                                       img(src = newUser.discordAvatarUrl) { style = "width:100%" }
+                                       p {
+                                               style = "text-align:center"
+                                               a(href = "/user/${newUser.id}") {
+                                                       +newUser.profileName
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+}