aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/Main.elm
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/Main.elm')
-rw-r--r--frontend/src/Main.elm62
1 files changed, 53 insertions, 9 deletions
diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm
index c1489bf..09a851d 100644
--- a/frontend/src/Main.elm
+++ b/frontend/src/Main.elm
@@ -14,6 +14,7 @@ import Http
14import Json.Encode as Encode 14import Json.Encode as Encode
15import Login 15import Login
16import Product 16import Product
17import Profile
17import Signup 18import Signup
18import Styles exposing (..) 19import Styles exposing (..)
19import Url 20import Url
@@ -48,6 +49,7 @@ type Route
48 | CartPage 49 | CartPage
49 | ProductPage Int 50 | ProductPage Int
50 | CheckoutPage 51 | CheckoutPage
52 | ProfilePage
51 | NotFoundPage 53 | NotFoundPage
52 54
53 55
@@ -61,6 +63,7 @@ parseRoute =
61 , P.map SignupPage (P.s "signup") 63 , P.map SignupPage (P.s "signup")
62 , P.map CheckoutPage (P.s "checkout") 64 , P.map CheckoutPage (P.s "checkout")
63 , P.map ProductPage (P.s "product" </> P.int) 65 , P.map ProductPage (P.s "product" </> P.int)
66 , P.map ProfilePage (P.s "profile")
64 ] 67 ]
65 68
66 69
@@ -74,6 +77,7 @@ type alias Model =
74 , signupModel : Signup.Model 77 , signupModel : Signup.Model
75 , cartModel : Cart.Model 78 , cartModel : Cart.Model
76 , checkoutModel : Checkout.Model 79 , checkoutModel : Checkout.Model
80 , profileModel : Profile.Model
77 } 81 }
78 82
79 83
@@ -100,8 +104,11 @@ init flags url key =
100 104
101 checkout = 105 checkout =
102 Checkout.init 106 Checkout.init
107
108 profile =
109 Profile.init
103 in 110 in
104 ( Model key url start login catalog product signup cart checkout, Cmd.none ) 111 ( Model key url start login catalog product signup cart checkout profile, Cmd.none )
105 112
106 113
107 114
@@ -117,6 +124,7 @@ type Msg
117 | SignupMessage Signup.Msg 124 | SignupMessage Signup.Msg
118 | CartMessage Cart.Msg 125 | CartMessage Cart.Msg
119 | CheckoutMessage Checkout.Msg 126 | CheckoutMessage Checkout.Msg
127 | ProfileMessage Profile.Msg
120 | LogoutPressed 128 | LogoutPressed
121 | LogoutSuccess (Result Http.Error ()) 129 | LogoutSuccess (Result Http.Error ())
122 130
@@ -174,6 +182,13 @@ update msg model =
174 in 182 in
175 ( { model | location = CheckoutPage }, cmd ) 183 ( { model | location = CheckoutPage }, cmd )
176 184
185 Just ProfilePage ->
186 let
187 cmd =
188 Cmd.map ProfileMessage Profile.tryFetchProfile
189 in
190 ( { model | location = ProfilePage }, cmd )
191
177 Just p -> 192 Just p ->
178 ( { model | location = p }, Cmd.none ) 193 ( { model | location = p }, Cmd.none )
179 194
@@ -229,10 +244,28 @@ update msg model =
229 ( cmn, cmd ) = 244 ( cmn, cmd ) =
230 Checkout.update cm model.checkoutModel 245 Checkout.update cm model.checkoutModel
231 246
247 redir =
248 case cmn.pageStatus of
249 Checkout.CheckedOut ->
250 Nav.replaceUrl model.key "/profile"
251
252 _ ->
253 Cmd.none
254
232 _ = 255 _ =
233 Debug.log "err" "received checkout message ..." 256 Debug.log "err" "received checkout message ..."
234 in 257 in
235 ( { model | checkoutModel = cmn }, Cmd.map CheckoutMessage cmd ) 258 ( { model | checkoutModel = cmn }, Cmd.batch [ Cmd.map CheckoutMessage cmd, redir ] )
259
260 ProfileMessage pm ->
261 let
262 ( pmn, cmd ) =
263 Profile.update pm model.profileModel
264
265 _ =
266 Debug.log "err" "recieved profile message"
267 in
268 ( { model | profileModel = pmn }, Cmd.map ProfileMessage cmd )
236 269
237 ProductMessage pm -> 270 ProductMessage pm ->
238 let 271 let
@@ -359,6 +392,15 @@ view model =
359 |> pageWrap model 392 |> pageWrap model
360 } 393 }
361 394
395 ProfilePage ->
396 { title = "Profile"
397 , body =
398 model.profileModel
399 |> Profile.view
400 |> Html.Styled.map ProfileMessage
401 |> pageWrap model
402 }
403
362 ProductPage item -> 404 ProductPage item ->
363 { title = "Product " ++ String.fromInt item 405 { title = "Product " ++ String.fromInt item
364 , body = 406 , body =
@@ -379,7 +421,7 @@ viewHeader model =
379 in 421 in
380 div 422 div
381 [ css 423 [ css
382 [ padding (px 40) 424 [ padding (px 30)
383 , paddingTop (px 3) 425 , paddingTop (px 3)
384 , paddingBottom (px 3) 426 , paddingBottom (px 3)
385 , textAlign left 427 , textAlign left
@@ -393,17 +435,19 @@ viewHeader model =
393 ] 435 ]
394 ) 436 )
395 links 437 links
396 ++ [ if model.loginModel.loginStatus /= Login.LoggedIn then 438 ++ (if model.loginModel.loginStatus /= Login.LoggedIn then
397 li [ css [ display inline ] ] [ headerLink [ href "/login" ] [ text "Login" ] ] 439 [ furbyButton [] [ headerLink [ href "/login" ] [ text "Login" ] ] ]
398 440
399 else 441 else
400 furbyButton [ onClick LogoutPressed ] [ text "Logout" ] 442 [ headerLink [ href "/profile" ] [ text "Profile" ]
401 ] 443 , furbyButton [ onClick LogoutPressed ] [ text "Logout" ]
444 ]
445 )
402 |> ul 446 |> ul
403 [ css 447 [ css
404 [ listStyle Css.none 448 [ listStyle Css.none
405 , padding (px 0) 449 , padding (px 0)
406 , margin (px 24) 450 , margin (px 12)
407 ] 451 ]
408 ] 452 ]
409 ] 453 ]