better separate featured bots from community bots - closes #7923

pull/7932/head
Thibault Duplessis 2021-01-15 15:21:19 +01:00
parent 591b6b5181
commit 5155e19776
3 changed files with 93 additions and 63 deletions

View File

@ -1,20 +1,22 @@
package views.html
package user
import controllers.routes
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.String.html.richText
import lila.user.User
import controllers.routes
object bots {
def apply(users: List[User])(implicit ctx: Context) = {
val title = s"${users.size} Online bots"
val sorted = users.sortBy { -_.playTime.??(_.total) }
views.html.base.layout(
title = title,
moreCss = frag(cssTag("slist"), cssTag("user.list")),
@ -22,59 +24,69 @@ object bots {
)(
main(cls := "page-menu bots")(
user.bits.communityMenu("bots"),
div(cls := "bots page-menu__content box")(
div(cls := "box__top")(h1(title)),
table(cls := "slist slist-pad")(
tbody(
users.sortBy { u =>
(if (u.isVerified) -1 else 1, -u.playTime.??(_.total))
} map { u =>
tr(
td(userLink(u)),
u.profile
.ifTrue(ctx.noKid)
.ifTrue(!u.marks.troll || ctx.is(u))
.flatMap(_.nonEmptyBio)
.map { bio =>
td(shorten(bio, 400))
} | td,
td(cls := "rating")(u.best3Perfs.map {
showPerfRating(u, _)
}),
u.playTime.fold(td) { playTime =>
td(
p(
cls := "text",
dataIcon := "C",
st.title := trans.tpTimeSpentPlaying.txt(showPeriod(playTime.totalPeriod))
)(showPeriod(playTime.totalPeriod)),
playTime.nonEmptyTvPeriod.map { tvPeriod =>
p(
cls := "text",
dataIcon := "1",
st.title := trans.tpTimeSpentOnTV.txt(showPeriod(tvPeriod))
)(showPeriod(tvPeriod))
}
)
},
if (ctx is u) td
else {
td(
a(
dataIcon := "U",
cls := List("button button-empty text" -> true),
st.title := trans.challengeToPlay.txt(),
href := s"${routes.Lobby.home()}?user=${u.username}#friend"
)(trans.play())
)
}
)
}
sorted.partition(_.isVerified) match {
case (featured, all) =>
div(cls := "bots page-menu__content")(
div(cls := "box bots__featured")(
div(cls := "box__top")(h1("Featured bots")),
botTable(featured)
),
div(cls := "box")(
div(cls := "box__top")(h1("Community bots")),
botTable(all)
)
)
)
)
}
)
)
}
private def botTable(users: List[User])(implicit ctx: Context) = table(cls := "slist slist-pad")(
tbody(
users.sortBy { u =>
(if (u.isVerified) -1 else 1, -u.playTime.??(_.total))
} map { u =>
tr(
td(userLink(u)),
u.profile
.ifTrue(ctx.noKid)
.ifTrue(!u.marks.troll || ctx.is(u))
.flatMap(_.nonEmptyBio)
.map { bio =>
td(shorten(bio, 400))
} | td,
td(cls := "rating")(u.best3Perfs.map {
showPerfRating(u, _)
}),
u.playTime.fold(td) { playTime =>
td(
p(
cls := "text",
dataIcon := "C",
st.title := trans.tpTimeSpentPlaying.txt(showPeriod(playTime.totalPeriod))
)(showPeriod(playTime.totalPeriod)),
playTime.nonEmptyTvPeriod.map { tvPeriod =>
p(
cls := "text",
dataIcon := "1",
st.title := trans.tpTimeSpentOnTV.txt(showPeriod(tvPeriod))
)(showPeriod(tvPeriod))
}
)
},
if (ctx is u) td
else {
td(
a(
dataIcon := "U",
cls := List("button button-empty text" -> true),
st.title := trans.challengeToPlay.txt(),
href := s"${routes.Lobby.home()}?user=${u.username}#friend"
)(trans.play())
)
}
)
}
)
)
}

View File

@ -11,6 +11,7 @@ $mq-not-xx-small: max-width 499px;
$mq-not-x-small: max-width 649px;
$mq-not-small: max-width 799px;
$mq-not-medium: max-width 979px;
$mq-not-large: max-width 1119px;
$mq-not-x-large: max-width 1259px;
/* Heights */

View File

@ -86,10 +86,38 @@ $user-list-width: 30ch;
}
.bots {
.box {
margin-bottom: 2vh;
}
table.slist {
border: none;
}
&__featured td {
padding: 2rem 1rem;
}
tr:last-child td {
padding-bottom: 2vh;
}
td:nth-child(3), td:nth-child(4) {
white-space: nowrap;
}
@include breakpoint($mq-not-small) {
td.rating {
display: none;
}
}
@include breakpoint($mq-not-large) {
td:nth-child(4) {
display: none;
}
}
.rating {
span {
&::before {
@ -99,15 +127,4 @@ $user-list-width: 30ch;
margin: 0 .3em;
}
}
@include breakpoint($mq-not-x-small) {
td.rating {
display: none;
}
}
@include breakpoint($mq-not-medium) {
td:nth-child(4) {
display: none;
}
}
}