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.elm125
1 files changed, 89 insertions, 36 deletions
diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm
index f1883a1..ea80921 100644
--- a/frontend/src/Main.elm
+++ b/frontend/src/Main.elm
@@ -5,14 +5,17 @@ import Browser.Navigation as Nav
5import Cart 5import Cart
6import Catalog 6import Catalog
7import Checkout 7import Checkout
8import Html exposing (..) 8import Css exposing (..)
9import Html.Attributes exposing (..) 9import Html
10import Html.Events exposing (..) 10import Html.Styled exposing (..)
11import Html.Styled.Attributes exposing (..)
12import Html.Styled.Events exposing (..)
11import Http 13import Http
12import Json.Encode as Encode 14import Json.Encode as Encode
13import Login 15import Login
14import Product 16import Product
15import Signup 17import Signup
18import Styles exposing (..)
16import Url 19import Url
17import Url.Parser as P exposing ((</>), Parser, int, oneOf, s, string) 20import Url.Parser as P exposing ((</>), Parser, int, oneOf, s, string)
18 21
@@ -276,56 +279,93 @@ subscriptions _ =
276view : Model -> Browser.Document Msg 279view : Model -> Browser.Document Msg
277view model = 280view model =
278 case model.location of 281 case model.location of
282 HomePage ->
283 { title = "Login"
284 , body =
285 -- model.loginModel
286 -- |> Login.view
287 -- |> Html.Styled.map LoginMessage
288 -- |> toUnstyled
289 -- |> List.singleton
290 div []
291 [ ul []
292 (List.map
293 (\l ->
294 li []
295 [ a [ href l ] [ text l ] ]
296 )
297 [ "/login", "/catalog", "/cart" ]
298 )
299 ]
300 |> toUnstyled
301 |> List.singleton
302 }
303
279 LoginPage -> 304 LoginPage ->
280 { title = "Login" 305 { title = "Login"
281 , body = [ Html.map LoginMessage (Login.view model.loginModel) ] 306 , body =
307 model.loginModel
308 |> Login.view
309 |> Html.Styled.map LoginMessage
310 |> toUnstyled
311 |> List.singleton
282 } 312 }
283 313
284 SignupPage -> 314 SignupPage ->
285 { title = "Signup" 315 { title = "Signup"
286 , body = [ Html.map SignupMessage (Signup.view model.signupModel) ]
287 }
288
289 HomePage ->
290 { title = "URL Interceptor"
291 , body = 316 , body =
292 [ text "The current URL is: " 317 model.signupModel
293 , b [] [ text (Url.toString model.url) ] 318 |> Signup.view
294 , ul [] 319 |> Html.Styled.map SignupMessage
295 [ viewLink "/login" 320 |> toUnstyled
296 , viewLink "/catalog" 321 |> List.singleton
297 , viewLink "/cart"
298 , viewLink "/signup"
299 ]
300 ]
301 } 322 }
302 323
303 NotFoundPage -> 324 NotFoundPage ->
304 { title = "404 - Not Found" 325 { title = "404 - Not Found"
305 , body = 326 , body =
306 [ text "404 - Not Found" 327 div []
307 , a [ href "/" ] [ text "Go back >" ] 328 [ text "404 - Not Found"
308 ] 329 , a [ href "/" ] [ text "Go back >" ]
330 ]
331 |> toUnstyled
332 |> List.singleton
309 } 333 }
310 334
311 CatalogPage -> 335 CatalogPage ->
312 { title = "Catalog" 336 { title = "Catalog"
313 , body = pageWrap model (Html.map CatalogMessage (Catalog.view model.catalogModel)) 337 , body =
338 model.catalogModel
339 |> Catalog.view
340 |> Html.Styled.map CatalogMessage
341 |> pageWrap model
314 } 342 }
315 343
316 CartPage -> 344 CartPage ->
317 { title = "Cart" 345 { title = "Cart"
318 , body = pageWrap model (Html.map CartMessage (Cart.view model.cartModel)) 346 , body =
347 model.cartModel
348 |> Cart.view
349 |> Html.Styled.map CartMessage
350 |> pageWrap model
319 } 351 }
320 352
321 CheckoutPage -> 353 CheckoutPage ->
322 { title = "Checkout" 354 { title = "Checkout"
323 , body = pageWrap model (Html.map CheckoutMessage (Checkout.view model.checkoutModel)) 355 , body =
356 model.checkoutModel
357 |> Checkout.view
358 |> Html.Styled.map CheckoutMessage
359 |> pageWrap model
324 } 360 }
325 361
326 ProductPage item -> 362 ProductPage item ->
327 { title = "Product " ++ String.fromInt item 363 { title = "Product " ++ String.fromInt item
328 , body = pageWrap model (Html.map ProductMessage (Product.view model.productModel)) 364 , body =
365 model.productModel
366 |> Product.view
367 |> Html.Styled.map ProductMessage
368 |> pageWrap model
329 } 369 }
330 370
331 371
@@ -333,36 +373,49 @@ viewHeader : Model -> Html Msg
333viewHeader model = 373viewHeader model =
334 let 374 let
335 links = 375 links =
336 [ ( "Home", "/" ) 376 [ ( "Catalog", "/catalog" )
337 , ( "Catalog", "/catalog" )
338 , ( "Cart", "/cart" ) 377 , ( "Cart", "/cart" )
339 ] 378 ]
340 in 379 in
341 div [] 380 div
381 [ css
382 [ padding (px 40)
383 , paddingTop (px 3)
384 , paddingBottom (px 3)
385 , textAlign left
386 , backgroundColor theme.secondary
387 ]
388 ]
342 [ List.map 389 [ List.map
343 (\( name, loc ) -> 390 (\( name, loc ) ->
344 li [] 391 li [ css [ display inline ] ]
345 [ a [ href loc ] [ text name ] 392 [ headerLink [ href loc ] [ text name ]
346 ] 393 ]
347 ) 394 )
348 links 395 links
349 ++ [ if model.loginModel.loginStatus /= Login.LoggedIn then 396 ++ [ if model.loginModel.loginStatus /= Login.LoggedIn then
350 li [] [ a [ href "/login" ] [ text "Login" ] ] 397 li [ css [ display inline ] ] [ headerLink [ href "/login" ] [ text "Login" ] ]
351 398
352 else 399 else
353 button [ onClick LogoutPressed ] [ text "Logout" ] 400 furbyButton [ onClick LogoutPressed ] [ text "Logout" ]
354 ] 401 ]
355 |> ul [] 402 |> ul
403 [ css
404 [ listStyle Css.none
405 , padding (px 0)
406 ]
407 ]
356 ] 408 ]
357 409
358 410
359pageWrap : Model -> Html Msg -> List (Html Msg) 411pageWrap : Model -> Html Msg -> List (Html.Html Msg)
360pageWrap model page = 412pageWrap model page =
361 [ div [] 413 div []
362 [ viewHeader model 414 [ viewHeader model
363 , page 415 , page
364 ] 416 ]
365 ] 417 |> toUnstyled
418 |> List.singleton
366 419
367 420
368viewLink : String -> Html msg 421viewLink : String -> Html msg