Skip to content

Commit

Permalink
visual tournament progress on homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 21, 2024
1 parent ceea64c commit 0278335
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
8 changes: 8 additions & 0 deletions modules/tournament/src/main/Tournament.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ case class Tournament(

def secondsToFinish = (finishesAt.toSeconds - nowSeconds).toInt.atLeast(0)

def progressPercent: Int =
if isCreated then 0
else if isFinished then 100
else
val total = minutes * 60
val remaining = secondsToFinish
100 - (remaining * 100 / total)

def pairingsClosed = secondsToFinish < math.max(30, math.min(clock.limitSeconds.value / 2, 120))

def isStillWorthEntering =
Expand Down
13 changes: 9 additions & 4 deletions modules/tournament/src/main/ui/TournamentUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@ final class TournamentUi(helpers: Helpers)(getTourName: GetTourName):
tours.map: tour =>
val visiblePlayers = (tour.nbPlayers >= 10).option(tour.nbPlayers)
tr(
td(cls := "name")(
td(
a(cls := "text", dataIcon := tournamentIcon(tour), href := routes.Tournament.show(tour.id)):
tour.name(full = false)
),
td(
if tour.isStarted then timeRemaining(tour.finishesAt)
else momentFromNow(tour.schedule.fold(tour.startsAt)(_.atInstant))
td(cls := "progress-td")(
span(cls := "progress")(
(
if tour.isStarted then timeRemaining(tour.finishesAt)
else momentFromNow(tour.schedule.fold(tour.startsAt)(_.atInstant))
) (cls := "progress__text"),
span(cls := "progress__bar", st.style := s"width:${tour.progressPercent}%")
)
),
td(tour.durationString),
tour.conditions.teamMember match
Expand Down
35 changes: 35 additions & 0 deletions ui/lobby/css/_box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,39 @@
&__blog .lobby__box__top {
border-bottom: $border;
}

.progress-td {
padding: 0.3em 0.4em;
}
.progress {
border-radius: 2em;
display: block;
position: relative;
width: 30ch;
height: 1.25em;

background: $m-bg-page--fade-40;
@include if-light {
background: $m-shade--fade-40;
}
@include if-transp {
background: $m-bg--fade-40;
}
overflow: hidden;
}
.progress__bar {
border-radius: 2em;
display: block;
height: 100%;
background: $m-primary_bg-page__mix-20--fade-70;
}
.progress__text {
position: absolute;
color: $c-font;
font-size: 0.9em;
top: 0;
width: 100%;
@include inline-start(1.5ch);
z-index: 3;
}
}

0 comments on commit 0278335

Please sign in to comment.