aboutsummaryrefslogtreecommitdiff
path: root/picarones-elm/src/Main.elm
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--picarones-elm/src/Main.elm18
1 files changed, 11 insertions, 7 deletions
diff --git a/picarones-elm/src/Main.elm b/picarones-elm/src/Main.elm
index 5066ad6..56cf48f 100644
--- a/picarones-elm/src/Main.elm
+++ b/picarones-elm/src/Main.elm
@@ -6,6 +6,7 @@ import Html.Attributes exposing (style, class, value, placeholder, src)
import Html.Events exposing (onInput, onClick)
import Html.Lazy exposing (lazy)
import List exposing (foldr)
+import Url.Parser exposing (Parser, (</>), string, fragment)
import Protocol exposing (decodeState, encodeState)
import Json.Decode as D
@@ -27,14 +28,15 @@ port recvPort : (String -> msg) -> Sub msg
port sendPort : String -> Cmd msg
+
{- STATE AND STATE TRANSITIONS -}
-- the main client state
-type alias Model = { slide : Int, max : Int }
+type alias Model = { slide : Int, max : Int, prefix : String }
-- start at the first slide, for now just assume that we have ten slides
-init : () -> (Model, Cmd Msg)
-init f = ( { slide = 0, max = 10 }, Cmd.none)
+init : (String, Int) -> (Model, Cmd Msg)
+init (url, max) = ( { slide = 0, max = max, prefix = url ++ "/"}, Cmd.none)
-- possible state transitions:
type Msg = GotMessage String
@@ -66,7 +68,7 @@ updateSlide f model =
-- our body consists of a slide container and a couple controls
body : Model -> Html Msg
body model = div []
- [ div [class "slides"] (slideView model.slide model.max)
+ [ div [class "slides"] (slideView model.slide model.max model.prefix)
, div [class "controls"]
[ button [ onClick PrevSlide ] [ text "←" ]
, text (String.fromInt (model.slide+1))
@@ -74,12 +76,14 @@ body model = div []
]
]
+
+
-- the slide view is just a list of img tags, one for each slide; note
-- that these are all loaded on startup, with visibility done through
-- z indices so we won't have lags while switching between them.
-slideView : Int -> Int -> List (Html Msg)
-slideView i max = List.range 0 (max - 1)
- |> List.map (\x -> ("example/" ++ (padNum 2 (x+1)) ++ ".png", x == i))
+slideView : Int -> Int -> String -> List (Html Msg)
+slideView i max prefix = List.range 0 (max - 1)
+ |> List.map (\x -> (prefix ++ (padNum 2 (x+1)) ++ ".png", x == i))
|> List.map (\(path,t) -> img [src path, onTop t] [])
onTop t = style "z-index" (String.fromInt (if t then 10 else 0))