diff options
| author | Joel Stålnacke <joel@saker.fi> | 2025-09-08 14:34:20 +0300 |
|---|---|---|
| committer | Joel Stålnacke <joel@saker.fi> | 2025-09-08 14:34:20 +0300 |
| commit | 341919abd73de642c364b1d82932bd038345dc68 (patch) | |
| tree | a64f5888e4a6d5fbd8f6c5666f9fb9b5745d85b9 | |
| parent | 1f3d65be843fda975a484c0c85cc0a0d03f5eb15 (diff) | |
TJ in more time units (WIP)
| -rw-r--r-- | Aamukampa.Core/Views.fs | 41 | ||||
| -rw-r--r-- | Aamukampa.Frontend/App.fs | 25 |
2 files changed, 55 insertions, 11 deletions
diff --git a/Aamukampa.Core/Views.fs b/Aamukampa.Core/Views.fs index a447688..b94e06f 100644 --- a/Aamukampa.Core/Views.fs +++ b/Aamukampa.Core/Views.fs @@ -1,7 +1,6 @@ namespace Aamukampa.Core.Views open System -open System.IO open Falco.Markup open Elem open Attr @@ -15,8 +14,8 @@ module Document = meta [ charset "utf-8" ] meta [ name "viewport"; content "width=device-width" ] Elem.title [] [ raw "Aamukampa" ] - script [ type' "module"; src (Path.Combine(Config.pathBase, "js/app.js")) ] [] - link [ rel "stylesheet"; href (Path.Combine(Config.pathBase, "styles.css")) ] + link [ rel "stylesheet"; href (sprintf "%s%s" Config.pathBase "styles.css") ] + script [ type' "module"; src (sprintf "%s%s" Config.pathBase "app.js") ] [] ] body [] [ documentBody @@ -29,13 +28,35 @@ module Main = TimeCompleted : TimeSpan } + let timeUnits model = + let round (p : int) (f : float) = Math.Round(f, p) + + div [ id "time-units" ] [ + yield! + ([ + "Vuosia", "tj-years", model.TimeLeft.TotalDays / 365.0 |> round 2 + "Kuukausia", "tj-months", model.TimeLeft.TotalDays / 30.0 |> round 2 + "Viikkoja", "tj-weeks", model.TimeLeft.TotalDays / 7.0 |> round 1 + "Tunteja", "tj-hours", model.TimeLeft.TotalHours |> round 1 + "Minuutteja", "tj-minutes", model.TimeLeft.TotalMinutes |> round 0 + "Sekunteja", "tj-seconds", model.TimeLeft.TotalSeconds |> round 0 + ] + |> List.map (fun (title, valueId, value) -> + div [] [ + span title + Elem.span [ id valueId ] [ + enc (string value) + ] + ])) + ] + let view model = main [] [ div [ class' "counter" ] [ Elem.span [ class' "counter_title" ] [ raw "Tänään jäljellä" ] - Elem.span [ class' "counter_value" ] [ + Elem.span [ id "tj"; class' "counter_value" ] [ enc (string <| Math.Ceiling model.TimeLeft.TotalDays) ] Elem.span [ class' "counter_mornings" ] [ @@ -60,12 +81,24 @@ module Main = ] ] + div [] [ + Elem.label [ for' "kontingent-select" ] [ raw "Saapumiserä:" ] + select [ id "kontingent-select" ] [ + option [ value "1/25" ] [ enc "1/25" ] + option [ value "2/25" ] [ enc "2/25" ] + option [ value "1/26" ] [ enc "1/26" ] + option [ value "2/26" ] [ enc "2/26" ] + ] + ] + Elem.p [ style "text-align: center; font-size: 1.5rem;" ] [ enc "2/25 255" ] + timeUnits model + // div [] [ // Elem.label [ for' "kontingent-select" ] [ raw "Saapumiserä:" ] // select [ id "kontingent-select" ] [ diff --git a/Aamukampa.Frontend/App.fs b/Aamukampa.Frontend/App.fs index 8c69d29..d388013 100644 --- a/Aamukampa.Frontend/App.fs +++ b/Aamukampa.Frontend/App.fs @@ -1,6 +1,7 @@ open System open Browser.Dom open Aamukampa.Core +open Falco.Markup DateTime.Now |> printfn "It is %O" @@ -8,13 +9,23 @@ DateTime.Now let k = kontingent 2 2025 let st = ThreeFourSeven -let currentTime = - // DateTime(2025, 7, 5) - // DateTime(2026, 6, 18) - // DateTime(2026, 6, 17) - DateTime.Today - // DateTime.Now - // Domain.getStartDate k |> Option.get +window.setInterval((fun () -> + let now = DateTime.Now + let tjElement = document.getElementById "tj" + let currentTj = + match Int32.TryParse(tjElement.innerText) with + | true, tj -> Some tj + | false, _ -> None + document.getElementById "time-units" + |> fun el -> + el.outerHTML <- + Views.Main.timeUnits { + TimeLeft = Domain.getTimeLeft k st now |> Option.get + TimeCompleted = Domain.getTimeCompleted k now |> Option.get + } |> renderHtml + ()), + 1000, [||]) + |> ignore // currentTime // |> Domain.getTimeLeft k st |
