aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Model
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/Model')
-rw-r--r--src/client/elm/Model/Init.elm17
-rw-r--r--src/client/elm/Model/InitResult.elm28
-rw-r--r--src/client/elm/Model/View.elm3
3 files changed, 43 insertions, 5 deletions
diff --git a/src/client/elm/Model/Init.elm b/src/client/elm/Model/Init.elm
index 7fccf00..5db038d 100644
--- a/src/client/elm/Model/Init.elm
+++ b/src/client/elm/Model/Init.elm
@@ -1,10 +1,13 @@
module Model.Init
( Init
+ , initDecoder
) where
-import Model.Payment exposing (Payments)
-import Model.Income exposing (Incomes)
-import Model.User exposing (Users, UserId)
+import Json.Decode as Json exposing ((:=))
+
+import Model.Payment exposing (Payments, paymentsDecoder)
+import Model.Income exposing (Incomes, incomesDecoder)
+import Model.User exposing (Users, UserId, usersDecoder, userIdDecoder)
type alias Init =
{ users : Users
@@ -12,3 +15,11 @@ type alias Init =
, payments : Payments
, incomes : Incomes
}
+
+initDecoder : Json.Decoder Init
+initDecoder =
+ Json.object4 Init
+ ("users" := usersDecoder)
+ ("me" := userIdDecoder)
+ ("payments" := paymentsDecoder)
+ ("incomes" := incomesDecoder)
diff --git a/src/client/elm/Model/InitResult.elm b/src/client/elm/Model/InitResult.elm
new file mode 100644
index 0000000..d1f1348
--- /dev/null
+++ b/src/client/elm/Model/InitResult.elm
@@ -0,0 +1,28 @@
+module Model.InitResult
+ ( InitResult(..)
+ , initResultDecoder
+ ) where
+
+import Json.Decode as Json exposing ((:=))
+
+import Model.Init exposing (Init, initDecoder)
+
+type InitResult =
+ InitEmpty
+ | InitSuccess Init
+ | InitError String
+
+initResultDecoder : Json.Decoder InitResult
+initResultDecoder = ("tag" := Json.string) `Json.andThen` initResultDecoderWithTag
+
+initResultDecoderWithTag : String -> Json.Decoder InitResult
+initResultDecoderWithTag tag =
+ case tag of
+ "InitEmpty" ->
+ Json.succeed InitEmpty
+ "InitSuccess" ->
+ Json.map InitSuccess ("contents" := initDecoder)
+ "InitError" ->
+ Json.map InitError ("contents" := Json.string)
+ _ ->
+ Json.fail <| "got " ++ tag ++ " for InitResult"
diff --git a/src/client/elm/Model/View.elm b/src/client/elm/Model/View.elm
index 9d64c73..475e826 100644
--- a/src/client/elm/Model/View.elm
+++ b/src/client/elm/Model/View.elm
@@ -8,6 +8,5 @@ import SignIn.Model as SignInModel
import LoggedIn.Model as LoggedInModel
type View =
- LoadingView
- | SignInView SignInModel.Model
+ SignInView SignInModel.Model
| LoggedInView LoggedInModel.Model