aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/Cart.elm
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/Cart.elm')
-rw-r--r--frontend/src/Cart.elm83
1 files changed, 59 insertions, 24 deletions
diff --git a/frontend/src/Cart.elm b/frontend/src/Cart.elm
index 44d5a0d..008d0bc 100644
--- a/frontend/src/Cart.elm
+++ b/frontend/src/Cart.elm
@@ -2,6 +2,7 @@ module Cart exposing (..)
2 2
3import Browser 3import Browser
4import Browser.Navigation as Nav 4import Browser.Navigation as Nav
5import Css exposing (..)
5import Html 6import Html
6import Html.Styled exposing (..) 7import Html.Styled exposing (..)
7import Html.Styled.Attributes exposing (..) 8import Html.Styled.Attributes exposing (..)
@@ -9,8 +10,8 @@ import Html.Styled.Events exposing (..)
9import Http 10import Http
10import Json.Decode as D 11import Json.Decode as D
11import Json.Encode as Encode 12import Json.Encode as Encode
12import Url 13import Styles exposing (..)
13import Url.Parser as P exposing ((</>), Parser, int, oneOf, s, string) 14import Utils exposing (..)
14 15
15 16
16type alias Product = 17type alias Product =
@@ -181,15 +182,24 @@ calculateTotal model =
181 182
182viewCartItemListing : CartListing -> Html Msg 183viewCartItemListing : CartListing -> Html Msg
183viewCartItemListing listing = 184viewCartItemListing listing =
184 div [] 185 -- div []
185 [ text listing.productItem.name 186 -- [ text listing.productItem.name
186 , div [] [ text <| Maybe.withDefault "" listing.productItem.kind ] 187 -- , div [] [ text <| Maybe.withDefault "" listing.productItem.kind ]
187 , div [] [ text <| Maybe.withDefault "" listing.productItem.description ] 188 -- , div [] [ text <| Maybe.withDefault "" listing.productItem.description ]
188 , div [] [ text <| String.fromFloat listing.productItem.price ] 189 -- , div [] [ text <| String.fromFloat listing.productItem.price ]
189 , div [] [ text <| String.fromInt listing.quantity ] 190 -- , div [] [ text <| String.fromInt listing.quantity ]
190 , div [] [ button [ onClick (AddToCartPressed listing.productItem.id) ] [ text "Add" ] ] 191 -- , div [] [ button [ onClick (AddToCartPressed listing.productItem.id) ] [ text "Add" ] ]
191 , div [] [ button [ onClick (RemoveFromCart listing.productItem.id) ] [ text "Remove" ] ] 192 -- , div [] [ button [ onClick (RemoveFromCart listing.productItem.id) ] [ text "Remove" ] ]
192 , div [] [ a [ href ("/product/" ++ String.fromInt listing.productItem.id) ] [ text "View Product" ] ] 193 -- , div [] [ a [ href ("/product/" ++ String.fromInt listing.productItem.id) ] [ text "View Product" ] ]
194 -- ]
195 tr []
196 [ td [] [ a [ href ("/product/" ++ String.fromInt listing.productItem.id) ] [ text listing.productItem.name ] ]
197 , td [] [ text <| String.fromFloat listing.productItem.price ]
198 , td []
199 [ furbyButton [ onClick (RemoveFromCart listing.productItem.id) ] [ div [ style "font-family" "monospace" ] [ text "-" ] ]
200 , text <| String.fromInt listing.quantity
201 , furbyButton [ onClick (AddToCartPressed listing.productItem.id) ] [ div [ style "font-family" "monospace" ] [ text "+" ] ]
202 ]
193 ] 203 ]
194 204
195 205
@@ -200,16 +210,41 @@ view model =
200 div [] [ text <| viewStatus Loading ] 210 div [] [ text <| viewStatus Loading ]
201 211
202 _ -> 212 _ ->
203 div [] 213 let
204 [ let 214 cart =
205 cart = 215 List.map viewCartItemListing model.products
206 List.map viewCartItemListing model.products 216
207 in 217 headings =
208 if List.isEmpty cart then 218 [ "Product Name", "Price (₹)", "Quantity" ]
209 text "No items in cart" 219 |> List.map (th [] << List.singleton << text)
210 220 in
211 else 221 if List.isEmpty cart then
212 ul [] cart 222 text "No items in cart"
213 , calculateTotal model |> String.fromFloat |> text 223
214 , a [ href "/checkout" ] [ text "Checkout" ] 224 else
215 ] 225 div
226 [ css
227 [ margin auto
228 , marginTop (pct 5)
229 , Css.width (pct 40)
230 ]
231 ]
232 [ div [ css [ bigHeading, marginBottom (px 20) ] ] [ text "Cart" ]
233 , Html.Styled.table
234 [ css
235 [ Css.width (pct 100)
236 , maxWidth (px 650)
237 , textAlign right
238 ]
239 ]
240 (tr [] headings
241 :: cart
242 ++ [ tr [ style "padding-top" "20px" ]
243 [ td [ style "border-top" "1px solid black" ] []
244 , td [ style "border-top" "1px solid black" ] [ div [] [ text "Cart total: " ] ]
245 , td [ style "border-top" "1px solid black" ] [ calculateTotal model |> String.fromFloat |> text ]
246 ]
247 ]
248 )
249 , a [ href "/checkout" ] [ text "Checkout" ]
250 ]