|
|
@@ -58,9 +58,9 @@ type alias ToolboxAccordion =
|
|
|
|
|
|
type SetLoadStatus
|
|
|
= CheckingLocalData
|
|
|
+ | NoLocalData
|
|
|
| HasLocalData Database.Database
|
|
|
| FetchingRemoteData
|
|
|
- | SavingRemoteData
|
|
|
|
|
|
|
|
|
type alias ChooseSetModel =
|
|
|
@@ -114,6 +114,8 @@ type Msg
|
|
|
| ToggleDeckList
|
|
|
| SetDeckSortMethod Deck.DeckSortMethod
|
|
|
| IOGotSets (Result String (List String))
|
|
|
+ | IOFetchSetData String
|
|
|
+ | IOGotSetData (Result String ( String, Maybe Database.Database ))
|
|
|
| PortReceiveDoesSetHaveLocalData String
|
|
|
|
|
|
|
|
|
@@ -185,18 +187,25 @@ update msg model =
|
|
|
|
|
|
markSetDataNotAvailable : String -> Dict String SetLoadStatus -> Dict String SetLoadStatus
|
|
|
markSetDataNotAvailable setCode =
|
|
|
- Dict.insert setCode FetchingRemoteData
|
|
|
+ Dict.insert setCode NoLocalData
|
|
|
in
|
|
|
case Database.decode unparsedData of
|
|
|
Ok ( setCode, Just db ) ->
|
|
|
( ChooseSet { mdl | sets = Maybe.map (markSetDataLoaded setCode db) mdl.sets }, Cmd.none )
|
|
|
|
|
|
Ok ( setCode, Nothing ) ->
|
|
|
- ( ChooseSet { mdl | sets = Maybe.map (markSetDataNotAvailable setCode) mdl.sets }, Cmd.none )
|
|
|
+ ( ChooseSet { mdl | sets = Maybe.map (markSetDataNotAvailable setCode) mdl.sets }
|
|
|
+ , Cmd.none
|
|
|
+ )
|
|
|
|
|
|
Err e ->
|
|
|
( Error { error = "Error decoding local set data (" ++ e ++ ")" }, Cmd.none )
|
|
|
|
|
|
+ IOFetchSetData setCode ->
|
|
|
+ ( ChooseSet { mdl | sets = Maybe.map (Dict.insert setCode FetchingRemoteData) mdl.sets }
|
|
|
+ , API.getSetData setCode IOGotSetData
|
|
|
+ )
|
|
|
+
|
|
|
_ ->
|
|
|
( ChooseSet mdl, Cmd.none )
|
|
|
|
|
|
@@ -260,6 +269,12 @@ update msg model =
|
|
|
IOGotSets _ ->
|
|
|
( Ready mdl, Cmd.none )
|
|
|
|
|
|
+ IOGotSetData _ ->
|
|
|
+ ( Ready mdl, Cmd.none )
|
|
|
+
|
|
|
+ IOFetchSetData _ ->
|
|
|
+ ( Ready mdl, Cmd.none )
|
|
|
+
|
|
|
PortReceiveDoesSetHaveLocalData _ ->
|
|
|
( Ready mdl, Cmd.none )
|
|
|
|
|
|
@@ -286,11 +301,38 @@ view model =
|
|
|
|
|
|
viewChooseSet : ChooseSetModel -> Html Msg
|
|
|
viewChooseSet model =
|
|
|
+ let
|
|
|
+ viewLoadStatus : String -> SetLoadStatus -> Html Msg
|
|
|
+ viewLoadStatus setCode s =
|
|
|
+ case s of
|
|
|
+ FetchingRemoteData ->
|
|
|
+ text "Loading..."
|
|
|
+
|
|
|
+ CheckingLocalData ->
|
|
|
+ text "Loading..."
|
|
|
+
|
|
|
+ NoLocalData ->
|
|
|
+ button [ onClick (IOFetchSetData setCode) ] [ text "Download" ]
|
|
|
+
|
|
|
+ HasLocalData database ->
|
|
|
+ button [] [ text "Open" ]
|
|
|
+ in
|
|
|
div [ class "w-full h-full bg-slate-100 flex justify-center items-center" ]
|
|
|
[ div [ class "max-w-2xl max-h-2xl" ]
|
|
|
[ case model.sets of
|
|
|
Just sets ->
|
|
|
- ul [] (List.map (\s -> li [] [ text s ]) (Dict.keys sets))
|
|
|
+ ul []
|
|
|
+ (List.map
|
|
|
+ (\s ->
|
|
|
+ case Dict.get s sets of
|
|
|
+ Just setStatus ->
|
|
|
+ li [] [ text s, viewLoadStatus s setStatus ]
|
|
|
+
|
|
|
+ Nothing ->
|
|
|
+ p [] [ text "Loading..." ]
|
|
|
+ )
|
|
|
+ (Dict.keys sets)
|
|
|
+ )
|
|
|
|
|
|
Nothing ->
|
|
|
p [] [ text "Loading..." ]
|