adds type variable for Api.Response value field

This commit is contained in:
2019-11-15 16:05:17 +01:00
parent 1eb4fdc188
commit 516006f352
2 changed files with 90 additions and 65 deletions

View File

@@ -87,9 +87,9 @@ init (Player navKey playerId) =
, Cmd.batch
[ Api.fetchPlayer GotPlayer playerId
, Api.fetchClaims GotClaims playerId
, fetchLoot (OfPlayer playerId)
, fetchLoot OfGroup
, fetchLoot OfShop
, Api.fetchLoot GotLoot (Api.OfPlayer playerId)
, Api.fetchLoot GotLoot Api.OfGroup
, Api.fetchLoot GotLoot Api.OfShop
]
)
@@ -173,13 +173,17 @@ viewHeaderBar title model =
[ renderIcon { icon = "fab fa-d-and-d", size = "medium", ratio = "2x" }
, span [ class "title is-4", style "padding-left" "0.4em" ] [ text title ]
]
, a [ class "navbar-burger is-active" ]
, a
[ class "navbar-burger"
, classList [ ( "is-active", model.state.menuOpen ) ]
, onClick SwitchMenuOpen
]
[ span [ attribute "aria-hidden" "true" ] []
, span [ attribute "aria-hidden" "true" ] []
, span [ attribute "aria-hidden" "true" ] []
]
]
, div [ class "navbar-menu is-active" ]
, div [ class "navbar-menu", classList [ ( "is-active", model.state.menuOpen ) ] ]
[ div [ class "navbar-end" ]
[ a [ class "navbar-item", href "/marchand" ]
[ renderIcon { icon = "fas fa-store-alt", ratio = "1x", size = "medium" }
@@ -344,8 +348,6 @@ view model =
]
)
]
, hr [] []
, section [ class "container" ] [ viewDebugSection model ]
]
@@ -733,10 +735,11 @@ viewControls mode content =
type Msg
= ApiMsg Api.Msg
| ClearNotification
| SwitchMenuOpen
| SetContent ChestContent
| SetSelection (Maybe Selection)
| SwitchSelectionState Int
| GotLoot ToChest (HttpResult Loot)
| GotLoot Api.ToChest (HttpResult Loot)
| GotClaims (HttpResult Claims)
| GotPlayer (HttpResult Api.Player)
| SearchTextChanged String
@@ -763,6 +766,15 @@ insensitiveContains substring string =
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
SwitchMenuOpen ->
let
state =
model.state
in
( { model | state = { state | menuOpen = not model.state.menuOpen } }
, Cmd.none
)
NewItemsFromList newLoot maybeErrors ->
let
state =
@@ -1031,13 +1043,13 @@ update msg model =
model.state
in
case dest of
OfPlayer _ ->
Api.OfPlayer _ ->
{ model | state = { state | playerLoot = loot } }
OfGroup ->
Api.OfGroup ->
{ model | state = { state | groupLoot = loot } }
OfShop ->
Api.OfShop ->
{ model | state = { state | merchantLoot = loot } }
, Cmd.none
)
@@ -1067,10 +1079,17 @@ setError error model =
let
state =
model.state
newError =
if error == "" then
Nothing
else
Just error
in
{ model
| state =
{ state | error = Just error }
{ state | error = newError }
}
@@ -1124,29 +1143,6 @@ applyUpdate u model =
{ model | claims = List.filter (\c -> c.id /= claim.id) model.claims }
type ToChest
= OfPlayer Int
| OfGroup
| OfShop
fetchLoot : ToChest -> Cmd Msg
fetchLoot dest =
let
url =
case dest of
OfPlayer id ->
"http://localhost:8088/api/players/" ++ String.fromInt id ++ "/loot"
OfShop ->
"http://localhost:8088/api/items"
OfGroup ->
"http://localhost:8088/api/players/0/loot"
in
Api.fetchLoot url (GotLoot dest)
-- Selection
-- Get list of selected items