@@ -2,22 +2,25 @@ port module Main exposing (..)
22
33import Browser
44import Browser.Navigation as Nav
5+ import Circle
56import Html exposing (..)
6- import Html.Attributes exposing (class , disabled , hidden , id , type_ , value )
7+ import Html.Attributes exposing (class , disabled , id , type_ , value )
78import Html.Events exposing (onClick , onInput , onSubmit )
89import Js.Commands
910import Js.Events
1011import Json.Decode
1112import Json.Encode
12- import Lib.Duration as Duration
13+ import Lib.Duration as Duration exposing ( Duration )
1314import Lib.Icons as Icons
1415import Lib.ListExtras exposing (assign , rotate , uncons )
16+ import Lib.Ratio
1517import Mobbers exposing (Mobber , Mobbers )
1618import Random
1719import Random.List
1820import SharedEvents
1921import Sound.Library
2022import Svg exposing (Svg , svg )
23+ import Svg.Attributes as Svg
2124import Task
2225import Time
2326import Url
5457
5558type ClockState
5659 = Off
57- | On { end : Time . Posix , ended : Bool }
60+ | On { end : Time . Posix , length : Duration , ended : Bool }
5861
5962
6063type AlarmState
@@ -149,7 +152,9 @@ update msg model =
149152
150153 StartWithAlarm sound ->
151154 ( model
152- , sendEvent <| SharedEvents . toJson <| SharedEvents . Started { time = model. now, alarm = sound }
155+ , sendEvent <|
156+ SharedEvents . toJson <|
157+ SharedEvents . Started { time = model. now, alarm = sound, length = Duration . ofSeconds 10 }
153158 )
154159
155160 StopSound ->
@@ -223,6 +228,7 @@ applyTo state event =
223228 | clock =
224229 On
225230 { end = Time . posixToMillis started. time + ( 10 * 1000 ) |> Time . millisToPosix
231+ , length = started. length
226232 , ended = False
227233 }
228234 }
@@ -247,7 +253,7 @@ applyTo state event =
247253 ( { state | mobbers = rotate state. mobbers }, Cmd . none )
248254
249255 ( SharedEvents . ShuffledMobbers mobbers, _ ) ->
250- ( { state | mobbers = mobbers ++ ( List . filter ( \ el -> not <| List . member el mobbers) state. mobbers) }, Cmd . none )
256+ ( { state | mobbers = mobbers ++ List . filter ( \ el -> not <| List . member el mobbers) state. mobbers }, Cmd . none )
251257
252258 _ ->
253259 ( state, Cmd . none )
@@ -286,13 +292,35 @@ view model =
286292 let
287293 action =
288294 detectAction model
295+
296+ totalWidth =
297+ 220
298+
299+ outerRadiant =
300+ 104
301+
302+ pomodoroCircle =
303+ Circle . Circle
304+ outerRadiant
305+ ( Circle . Coordinates ( outerRadiant + 6 ) ( outerRadiant + 6 ))
306+ ( Circle . Stroke 10 " #999" )
307+
308+ mobCircle =
309+ Circle . inside pomodoroCircle <| Circle . Stroke 18 " #666"
289310 in
290311 { title = " Mob Time"
291312 , body =
292313 [ div [ class " container" ]
293314 [ header []
294315 [ section []
295- [ svg [ id " circles" ] []
316+ [ svg
317+ [ id " circles"
318+ , Svg . width <| String . fromInt totalWidth
319+ , Svg . height <| String . fromInt totalWidth
320+ ]
321+ <|
322+ Circle . draw pomodoroCircle Lib . Ratio . full
323+ ++ Circle . draw mobCircle ( clockRatio model)
296324 , button
297325 [ id " action"
298326 , class action. class
@@ -344,6 +372,18 @@ view model =
344372 }
345373
346374
375+ clockRatio : Model -> Lib .Ratio .Ratio
376+ clockRatio model =
377+ case model. clock of
378+ Off ->
379+ Lib . Ratio . full
380+
381+ On on ->
382+ Duration . div ( Duration . between model. now on. end) on. length
383+ |> ( (-) 1 )
384+ |> Lib . Ratio . from
385+
386+
347387mobberView : ( Maybe String , Maybe Mobber ) -> Maybe (Html Msg )
348388mobberView ( role, maybeMobber ) =
349389 maybeMobber
0 commit comments