diff options
author | Akshay <[email protected]> | 2020-12-26 17:23:44 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2020-12-26 17:23:44 +0000 |
commit | 546c3360c0d854d5c91430944e0f059a5001e986 (patch) | |
tree | a21230e564d09e8319503911ade8c9ac69c76fca /frontend/src/Product.elm | |
parent | 2da02aac8a05ad82fdd6876c9ff6c0586efba10d (diff) |
add styles to catalog and product
Diffstat (limited to 'frontend/src/Product.elm')
-rw-r--r-- | frontend/src/Product.elm | 144 |
1 files changed, 126 insertions, 18 deletions
diff --git a/frontend/src/Product.elm b/frontend/src/Product.elm index b97a847..79256cc 100644 --- a/frontend/src/Product.elm +++ b/frontend/src/Product.elm | |||
@@ -2,13 +2,16 @@ module Product exposing (..) | |||
2 | 2 | ||
3 | import Browser | 3 | import Browser |
4 | import Browser.Navigation as Nav | 4 | import Browser.Navigation as Nav |
5 | import Css exposing (..) | ||
5 | import Html | 6 | import Html |
6 | import Html.Styled exposing (..) | 7 | import Html.Styled exposing (..) |
7 | import Html.Styled.Attributes exposing (..) | 8 | import Html.Styled.Attributes exposing (..) |
8 | import Html.Styled.Events exposing (..) | 9 | import Html.Styled.Events exposing (..) |
9 | import Http | 10 | import Http |
11 | import Icons exposing (..) | ||
10 | import Json.Decode as D | 12 | import Json.Decode as D |
11 | import Json.Encode as Encode | 13 | import Json.Encode as Encode |
14 | import Styles exposing (..) | ||
12 | import Url | 15 | import Url |
13 | import Url.Parser as P exposing ((</>), Parser, int, oneOf, s, string) | 16 | import Url.Parser as P exposing ((</>), Parser, int, oneOf, s, string) |
14 | import Utils exposing (..) | 17 | import Utils exposing (..) |
@@ -77,7 +80,7 @@ type Msg | |||
77 | 80 | ||
78 | init : Model | 81 | init : Model |
79 | init = | 82 | init = |
80 | Model NotLoaded emptyProduct [] 0 "" NotSubmitted | 83 | Model NotLoaded emptyProduct [] 5 "" NotSubmitted |
81 | 84 | ||
82 | 85 | ||
83 | update : Msg -> Model -> ( Model, Cmd Msg ) | 86 | update : Msg -> Model -> ( Model, Cmd Msg ) |
@@ -251,12 +254,19 @@ viewStatus s = | |||
251 | 254 | ||
252 | viewProduct : Product -> Html Msg | 255 | viewProduct : Product -> Html Msg |
253 | viewProduct p = | 256 | viewProduct p = |
254 | div [] | 257 | div |
255 | [ div [] [ text p.name ] | 258 | [ css |
256 | , div [] [ text <| Maybe.withDefault "" p.kind ] | 259 | [ marginBottom (px 20) |
257 | , div [] [ text <| Maybe.withDefault "" p.description ] | 260 | , padding (px 20) |
258 | , div [] [ text <| String.fromFloat p.price ] | 261 | , Css.width (pct 100) |
259 | , div [] | 262 | ] |
263 | ] | ||
264 | [ div | ||
265 | [ css | ||
266 | [ float left | ||
267 | , Css.width (pct 50) | ||
268 | ] | ||
269 | ] | ||
260 | [ modelViewer | 270 | [ modelViewer |
261 | [ cameraControls | 271 | [ cameraControls |
262 | , autoRotate | 272 | , autoRotate |
@@ -267,16 +277,96 @@ viewProduct p = | |||
267 | ] | 277 | ] |
268 | [] | 278 | [] |
269 | ] | 279 | ] |
280 | , div | ||
281 | [ css | ||
282 | [ float left | ||
283 | , Css.width (pct 50) | ||
284 | ] | ||
285 | ] | ||
286 | [ div | ||
287 | [ css | ||
288 | [ cardSecondaryText | ||
289 | , paddingBottom (px 3) | ||
290 | , fontVariant smallCaps | ||
291 | ] | ||
292 | ] | ||
293 | [ text <| Maybe.withDefault "" p.kind ] | ||
294 | , div | ||
295 | [ css | ||
296 | [ cardPrimaryText | ||
297 | , paddingBottom (px 12) | ||
298 | ] | ||
299 | ] | ||
300 | [ text p.name ] | ||
301 | , div | ||
302 | [ css | ||
303 | [ cardSupportingText | ||
304 | , paddingBottom (px 6) | ||
305 | ] | ||
306 | ] | ||
307 | [ text <| Maybe.withDefault "No description provided" p.description ] | ||
308 | , div | ||
309 | [ css | ||
310 | [ fontWeight bold | ||
311 | , fontSize (px 14) | ||
312 | , money | ||
313 | ] | ||
314 | ] | ||
315 | [ text <| String.fromFloat p.price | ||
316 | , div [] | ||
317 | [ furbyButton [ onClick AddToCartPressed ] [ text "Add To Cart" ] | ||
318 | ] | ||
319 | ] | ||
320 | ] | ||
321 | , div [ style "clear" "both" ] [] | ||
270 | ] | 322 | ] |
271 | 323 | ||
272 | 324 | ||
325 | viewStarRating : Int -> Html Msg | ||
326 | viewStarRating i = | ||
327 | div [] | ||
328 | (List.repeat i starIcon) | ||
329 | |||
330 | |||
273 | viewRating : Rating -> Html Msg | 331 | viewRating : Rating -> Html Msg |
274 | viewRating r = | 332 | viewRating r = |
275 | div [] | 333 | -- div [] |
276 | [ text <| r.customerName ++ " posted on " | 334 | -- [ text <| r.customerName ++ " posted on " |
277 | , text <| r.commentDate ++ " " | 335 | -- , text <| r.commentDate ++ " " |
278 | , text <| Maybe.withDefault "" r.commentText | 336 | -- , text <| Maybe.withDefault "" r.commentText |
279 | , text <| " Stars: " ++ String.fromInt r.stars | 337 | -- , text <| " Stars: " ++ String.fromInt r.stars |
338 | -- ] | ||
339 | div | ||
340 | [ css | ||
341 | [ border3 (px 1) solid theme.primary | ||
342 | , borderRadius (px 4) | ||
343 | , marginBottom (px 20) | ||
344 | , padding (px 20) | ||
345 | ] | ||
346 | ] | ||
347 | [ div | ||
348 | [ css | ||
349 | [ fontSize (px 16) | ||
350 | , fontWeight bold | ||
351 | , paddingBottom (px 3) | ||
352 | ] | ||
353 | ] | ||
354 | [ text r.customerName ] | ||
355 | , viewStarRating r.stars | ||
356 | , div | ||
357 | [ css | ||
358 | [ cardSecondaryText | ||
359 | , paddingBottom (px 12) | ||
360 | ] | ||
361 | ] | ||
362 | [ text <| "Reviewed on " ++ r.commentDate ] | ||
363 | , if r.commentText /= Nothing then | ||
364 | div | ||
365 | [ css [ cardSupportingText ] ] | ||
366 | [ text <| Maybe.withDefault "" <| r.commentText ] | ||
367 | |||
368 | else | ||
369 | text "" | ||
280 | ] | 370 | ] |
281 | 371 | ||
282 | 372 | ||
@@ -290,7 +380,7 @@ viewStars = | |||
290 | ul [] | 380 | ul [] |
291 | (List.map | 381 | (List.map |
292 | (\i -> button [ onClick (AddRatingStars i) ] [ text <| String.fromInt i ]) | 382 | (\i -> button [ onClick (AddRatingStars i) ] [ text <| String.fromInt i ]) |
293 | [ 0, 1, 2, 3, 4, 5 ] | 383 | [ 1, 2, 3, 4, 5 ] |
294 | ) | 384 | ) |
295 | 385 | ||
296 | 386 | ||
@@ -301,9 +391,30 @@ view model = | |||
301 | div [] [ text <| viewStatus Loading ] | 391 | div [] [ text <| viewStatus Loading ] |
302 | 392 | ||
303 | _ -> | 393 | _ -> |
304 | div [] | 394 | div |
395 | [ css | ||
396 | [ Css.width (pct 60) | ||
397 | , margin auto | ||
398 | ] | ||
399 | ] | ||
305 | [ div [] [ viewProduct model.listing ] | 400 | [ div [] [ viewProduct model.listing ] |
306 | , ul [] (List.map viewRating model.ratings) | 401 | , div |
402 | [ css | ||
403 | [ cardPrimaryText | ||
404 | ] | ||
405 | ] | ||
406 | [ text "User Reviews" ] | ||
407 | , if model.ratings == [] then | ||
408 | text "Be the first to add a review." | ||
409 | |||
410 | else | ||
411 | ul | ||
412 | [ css | ||
413 | [ padding (px 0) | ||
414 | , listStyle Css.none | ||
415 | ] | ||
416 | ] | ||
417 | (List.map viewRating model.ratings) | ||
307 | , div [] [ text "Add Rating: " ] | 418 | , div [] [ text "Add Rating: " ] |
308 | , div [] | 419 | , div [] |
309 | [ viewStars | 420 | [ viewStars |
@@ -311,9 +422,6 @@ view model = | |||
311 | , button [ onClick AddRatingPressed ] [ text "Submit Rating" ] | 422 | , button [ onClick AddRatingPressed ] [ text "Submit Rating" ] |
312 | ] | 423 | ] |
313 | , div [] | 424 | , div [] |
314 | [ button [ onClick AddToCartPressed ] [ text "Add To Cart" ] | ||
315 | ] | ||
316 | , div [] | ||
317 | [ a [ href "/catalog" ] [ text "Back to catalog" ] | 425 | [ a [ href "/catalog" ] [ text "Back to catalog" ] |
318 | ] | 426 | ] |
319 | ] | 427 | ] |