Skip to content

Commit

Permalink
Better hilighting of the active draw when there are no active games, …
Browse files Browse the repository at this point in the history
…and when there are active games, use that instead for hilighting the entire row.
  • Loading branch information
rapind committed Nov 6, 2024
1 parent 456a17a commit 152def4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion prod.min.js

Large diffs are not rendered by default.

55 changes: 26 additions & 29 deletions src/Results.elm
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ type alias Event =
, spares : List Spare
, stages : List Stage
, draws : List Draw
, activeDrawId : Maybe Int
}


Expand Down Expand Up @@ -325,7 +326,6 @@ type Tiebreaker
type alias Draw =
{ id : Int
, startsAt : String
, recent : Bool
, label : String
, attendance : Int
, drawSheets : List (Maybe String)
Expand Down Expand Up @@ -642,6 +642,7 @@ decodeEvent =
|> optional "spares" (list decodeSpare) []
|> optional "stages" (list decodeStage) []
|> optional "draws" (list decodeDraw) []
|> optional "active_draw_id" (nullable int) Nothing


decodeTeam : Decoder Team
Expand Down Expand Up @@ -777,7 +778,6 @@ decodeDraw =
Decode.succeed Draw
|> required "id" int
|> required "starts_at" string
|> optional "recent" bool False
|> required "label" string
|> optional "attendance" int 0
|> required "draw_sheets" (list (nullable string))
Expand Down Expand Up @@ -3344,14 +3344,18 @@ viewSpares flags translations event =
viewDraws : Theme -> List Translation -> EventConfig -> Event -> Element Msg
viewDraws theme translations eventConfig event =
let
noActiveGames =
List.filter (\g -> g.state == GameActive) (gamesFromStages event.stages)
|> List.isEmpty

drawState : Draw -> DrawState
drawState draw =
let
findGame gameId =
gamesFromStages event.stages
|> List.Extra.find (\g -> Just g.id == gameId)

hasActiveGame =
drawHasActiveGame =
let
isActiveGame game =
List.any (\g -> g.id == game.id && g.state == GameActive) (gamesFromStages event.stages)
Expand All @@ -3373,16 +3377,13 @@ viewDraws theme translations eventConfig event =
|> List.isEmpty
|> not
in
if hasActiveGame then
if (noActiveGames && event.activeDrawId == Just draw.id) || drawHasActiveGame then
-- Highlight the active (closest) draw if there are no active games, or the current
-- draw is it has an active game.
DrawActive

else if hasPendingGame then
-- if there's a pending game, and the draw start time has passed recently, then we assume it is the active draw.
if draw.recent then
DrawActive

else
DrawPending
DrawPending

else
DrawComplete
Expand Down Expand Up @@ -3476,12 +3477,6 @@ viewDraws theme translations eventConfig event =
_ ->
Font.color theme.primary
, El.focused [ Background.color theme.white ]
, case game.state of
GameActive ->
Font.bold

_ ->
Font.regular
]
{ onPress = Just (NavigateTo (gameUrl event.id game.id))
, label = text gameNameWithResult
Expand Down Expand Up @@ -3513,20 +3508,22 @@ viewDraws theme translations eventConfig event =

tableCell align drawState_ content =
row
[ El.paddingXY 12 16
, Border.widthEach { bottom = 1, left = 0, right = 0, top = 0 }
, Border.color theme.grey
, El.htmlAttribute (class "cio__event_draws_cell")
, case drawState_ of
DrawComplete ->
Background.color theme.greyLightest

DrawActive ->
Background.color theme.greyLight
([ El.paddingXY 12 16
, Border.widthEach { bottom = 1, left = 0, right = 0, top = 0 }
, Border.color theme.grey
, El.htmlAttribute (class "cio__event_draws_cell")
]
++ (case drawState_ of
DrawActive ->
[ Font.bold
, Background.color theme.greyLight
, Border.widthEach { bottom = 2, left = 0, right = 0, top = 1 }
]

DrawPending ->
Background.color theme.transparent
]
_ ->
[]
)
)
[ el [ align ] content ]

labelColumn =
Expand Down

0 comments on commit 152def4

Please sign in to comment.