aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Main.elm
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2017-09-13 21:29:15 +0200
committerNoah Loomans <noahloomans@gmail.com>2017-09-13 21:29:15 +0200
commite87bf34e06f8bec3c6622102528c2d685b3cbb5b (patch)
treeeadfe43844faf52293f293ab37d9d621b6821329 /src/client/elm/Main.elm
parent3fb86482404e11942cd83c3500a297a3991db0e4 (diff)
Add some basic elm
Diffstat (limited to 'src/client/elm/Main.elm')
-rw-r--r--src/client/elm/Main.elm65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/client/elm/Main.elm b/src/client/elm/Main.elm
new file mode 100644
index 0000000..8e1e9c8
--- /dev/null
+++ b/src/client/elm/Main.elm
@@ -0,0 +1,65 @@
+module Main exposing (..)
+
+-- import Html.Attributes exposing (..)
+import Html exposing (..)
+import Json.Decode exposing (string, Decoder)
+import Json.Decode.Pipeline exposing (decode, required)
+
+
+main : Program Flags Model msg
+main =
+ Html.programWithFlags
+ { init = init
+ , update = update
+ , view = view
+ , subscriptions = subscriptions
+ }
+
+type alias Flags = Json.Decode.Value
+
+
+type alias Model =
+ { users : List User
+ }
+
+
+type alias User =
+ { type_ : String
+ , value : String
+ }
+
+
+type UserType
+ = Class
+ | Teacher
+ | Room
+ | Student
+
+init : Flags -> ( Model, Cmd msg )
+init flags =
+ case Json.Decode.decodeValue decodeUsers flags of
+ Ok user ->
+ (Model user, Cmd.none)
+
+ Err err ->
+ Debug.crash err
+
+decodeUsers : Decoder (List User)
+decodeUsers = Json.Decode.list decodeUser
+
+decodeUser : Decoder User
+decodeUser =
+ decode User
+ |> required "type" string
+ |> required "value" string
+
+update : msg -> Model -> (Model, Cmd msg)
+update msg model = (model, Cmd.none)
+
+view : Model -> Html msg
+view model =
+ text <| toString model
+
+subscriptions : Model -> Sub msg
+subscriptions model =
+ Sub.none \ No newline at end of file