Display collection statistics in footer
This commit is contained in:
parent
362bef913c
commit
f7277eb250
2 changed files with 55 additions and 1 deletions
|
@ -5,6 +5,7 @@ import Browser.Dom
|
||||||
import Browser.Events
|
import Browser.Events
|
||||||
import Browser.Navigation
|
import Browser.Navigation
|
||||||
import Card
|
import Card
|
||||||
|
import Collection
|
||||||
import Color
|
import Color
|
||||||
import Dict
|
import Dict
|
||||||
import Element as E
|
import Element as E
|
||||||
|
@ -47,6 +48,7 @@ type alias Model =
|
||||||
, criteria : Criteria
|
, criteria : Criteria
|
||||||
, cardPage : CardPage
|
, cardPage : CardPage
|
||||||
, activeCard : Maybe Card.Card
|
, activeCard : Maybe Card.Card
|
||||||
|
, collectionStatistics : Maybe Collection.Statistics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +60,7 @@ type Msg
|
||||||
| UpdateCriteria CriteriaMsg
|
| UpdateCriteria CriteriaMsg
|
||||||
| Search
|
| Search
|
||||||
| GetPage Url.Url
|
| GetPage Url.Url
|
||||||
|
| GotStatistics (Result Http.Error Collection.Statistics)
|
||||||
| FoundCards (Result Http.Error (Paginated.Page Card.Card))
|
| FoundCards (Result Http.Error (Paginated.Page Card.Card))
|
||||||
| ShowCardDetails Card.Card
|
| ShowCardDetails Card.Card
|
||||||
| ClearCardDetails
|
| ClearCardDetails
|
||||||
|
@ -148,6 +151,14 @@ loadPage url =
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
getCollectionStatistics : Cmd Msg
|
||||||
|
getCollectionStatistics =
|
||||||
|
Http.get
|
||||||
|
{ url = Url.Builder.absolute [ "collection" ] []
|
||||||
|
, expect = Http.expectJson GotStatistics Collection.decodeStatistics
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
parseUrl : Url.Parser.Parser (Criteria -> a) a
|
parseUrl : Url.Parser.Parser (Criteria -> a) a
|
||||||
parseUrl =
|
parseUrl =
|
||||||
let
|
let
|
||||||
|
@ -204,9 +215,11 @@ init _ url key =
|
||||||
, criteria = criteria
|
, criteria = criteria
|
||||||
, cardPage = Loading Paginated.empty
|
, cardPage = Loading Paginated.empty
|
||||||
, activeCard = Nothing
|
, activeCard = Nothing
|
||||||
|
, collectionStatistics = Nothing
|
||||||
}
|
}
|
||||||
, Cmd.batch
|
, Cmd.batch
|
||||||
[ search criteria
|
[ search criteria
|
||||||
|
, getCollectionStatistics
|
||||||
, Task.perform
|
, Task.perform
|
||||||
(\x ->
|
(\x ->
|
||||||
ViewportChanged
|
ViewportChanged
|
||||||
|
@ -287,6 +300,12 @@ update msg model =
|
||||||
GetPage url ->
|
GetPage url ->
|
||||||
( { model | cardPage = toLoading model.cardPage }, loadPage (Url.toString url) )
|
( { model | cardPage = toLoading model.cardPage }, loadPage (Url.toString url) )
|
||||||
|
|
||||||
|
GotStatistics (Ok statistics) ->
|
||||||
|
( { model | collectionStatistics = Just statistics }, Cmd.none )
|
||||||
|
|
||||||
|
GotStatistics (Err _) ->
|
||||||
|
( model, Cmd.none )
|
||||||
|
|
||||||
FoundCards (Ok cardPage) ->
|
FoundCards (Ok cardPage) ->
|
||||||
( { model | cardPage = Ready cardPage }, Cmd.none )
|
( { model | cardPage = Ready cardPage }, Cmd.none )
|
||||||
|
|
||||||
|
@ -755,10 +774,26 @@ view model =
|
||||||
, E.el
|
, E.el
|
||||||
[ E.height (E.px 50)
|
[ E.height (E.px 50)
|
||||||
, E.width E.fill
|
, E.width E.fill
|
||||||
|
, E.padding 10
|
||||||
|
, Font.color colors.text
|
||||||
, Background.color colors.navBar
|
, Background.color colors.navBar
|
||||||
, E.alignBottom
|
, E.alignBottom
|
||||||
]
|
]
|
||||||
<|
|
<|
|
||||||
|
case model.collectionStatistics of
|
||||||
|
Just statistics ->
|
||||||
|
E.el [ E.centerY, Font.size 16, Font.italic ] <|
|
||||||
|
E.text <|
|
||||||
|
String.concat
|
||||||
|
[ String.fromInt statistics.cards
|
||||||
|
, " cards in collection spanning "
|
||||||
|
, String.fromInt statistics.sets
|
||||||
|
, " sets (Estimated value: $"
|
||||||
|
, statistics.value
|
||||||
|
, ")"
|
||||||
|
]
|
||||||
|
|
||||||
|
Nothing ->
|
||||||
E.none
|
E.none
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
19
www/src/Collection.elm
Normal file
19
www/src/Collection.elm
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
module Collection exposing (..)
|
||||||
|
|
||||||
|
import Json.Decode
|
||||||
|
import Json.Decode.Pipeline as JDP
|
||||||
|
|
||||||
|
|
||||||
|
type alias Statistics =
|
||||||
|
{ cards : Int
|
||||||
|
, sets : Int
|
||||||
|
, value : String
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
decodeStatistics : Json.Decode.Decoder Statistics
|
||||||
|
decodeStatistics =
|
||||||
|
Json.Decode.succeed Statistics
|
||||||
|
|> JDP.required "cards" Json.Decode.int
|
||||||
|
|> JDP.required "sets" Json.Decode.int
|
||||||
|
|> JDP.required "value" Json.Decode.string
|
Loading…
Reference in a new issue