impls basic Wealth editing

This commit is contained in:
2019-11-19 14:37:46 +01:00
parent 44e44c70bf
commit 1cac3e33fd
2 changed files with 74 additions and 9 deletions

View File

@@ -334,6 +334,7 @@ type RequestData
| BuyPayload Loot (Maybe Float) (List (Maybe Float)) | BuyPayload Loot (Maybe Float) (List (Maybe Float))
| GrabPayload Loot | GrabPayload Loot
| AddPayload String Loot | AddPayload String Loot
| WealthPayload Float
zip xs ys = zip xs ys =
@@ -396,6 +397,9 @@ buildPayload data =
, ( "source_name", E.string sourceName ) , ( "source_name", E.string sourceName )
] ]
WealthPayload amount ->
E.float amount
confirmAction : String -> RequestData -> Cmd Msg confirmAction : String -> RequestData -> Cmd Msg
confirmAction id data = confirmAction id data =
@@ -421,6 +425,11 @@ confirmAction id data =
( "http://localhost:8088/api/players/" ++ id ++ "/claims" ( "http://localhost:8088/api/players/" ++ id ++ "/claims"
, "POST" , "POST"
) )
WealthPayload _ ->
( "http://localhost:8088/api/players/" ++ id ++ "/wealth"
, "PUT"
)
in in
Http.request Http.request
{ method = method { method = method

View File

@@ -43,6 +43,9 @@ type alias State =
, itemList : Maybe (List String) , itemList : Maybe (List String)
-- , inventoryItems : Loot -- , inventoryItems : Loot
, editWealth : Bool
, wealthAmount : String
-- Fetched on init -- Fetched on init
, player : Api.Player , player : Api.Player
, playerLoot : Loot , playerLoot : Loot
@@ -80,6 +83,8 @@ init (Player navKey playerId) =
Nothing Nothing
Nothing Nothing
Nothing Nothing
False
"0.0"
Api.blankPlayer Api.blankPlayer
[] []
[] []
@@ -225,8 +230,8 @@ viewHeaderBar title model =
-- PLAYER BAR -- PLAYER BAR
viewPlayerBar : Api.Player -> List (Html Msg) -> Html Msg viewPlayerBar : Api.Player -> List (Html Msg) -> ( Bool, String ) -> Html Msg
viewPlayerBar player actionControls = viewPlayerBar player actionControls ( editing, amount ) =
section [ class "hero is-dark is-bold" ] section [ class "hero is-dark is-bold" ]
[ div [ class "hero-body" ] [ div [ class "hero-body" ]
[ div [ class "level container is-mobile" ] [ div [ class "level container is-mobile" ]
@@ -235,10 +240,15 @@ viewPlayerBar player actionControls =
[ p [ class "title is-3" ] [ text player.name ] ] [ p [ class "title is-3" ] [ text player.name ] ]
, div [ class "level-item" ] , div [ class "level-item" ]
[ span [ class "icon is-large" ] [ i [ class "fas fa-2x fa-piggy-bank" ] [] ] [ span [ class "icon is-large" ] [ i [ class "fas fa-2x fa-piggy-bank" ] [] ]
, span [ class "icon" ] [ i [ class "fas fa-tools" ] [] ] , span [ class "icon", onClick EditWealth ] [ i [ class "fas fa-tools" ] [] ]
] ]
] ]
++ viewWealth player.wealth ++ (if editing then
viewUpdateWealth amount
else
viewWealth player.wealth
)
++ (if player.debt > 0 then ++ (if player.debt > 0 then
[ div [ class "level-item" ] [ div [ class "level-item" ]
[ p [ class "heading is-size-4 has-text-danger" ] [ p [ class "heading is-size-4 has-text-danger" ]
@@ -256,9 +266,18 @@ viewPlayerBar player actionControls =
] ]
viewUpdateWealth = viewUpdateWealth amount =
[ input [ class "level-item" ] [] let
, button [ class "level-item button" ] [ text "Ok" ] isAmountValid =
case String.toFloat amount of
Just _ ->
True
Nothing ->
False
in
[ input [ class "level-item", class "input", classList [ ( "is-danger", not isAmountValid ) ], value amount, onInput AmountChanged ] []
, button [ class "level-item button", onClick ConfirmEditWealth ] [ text "Ok" ]
] ]
@@ -307,7 +326,7 @@ view model =
"Marchand" "Marchand"
NewLoot -> NewLoot ->
"Nouveau trésor :)" "Nouveau trésor"
shownItems = shownItems =
selectContent model selectContent model
@@ -420,7 +439,7 @@ view model =
(\i -> String.toLower i.name |> String.contains (String.toLower model.searchText)) (\i -> String.toLower i.name |> String.contains (String.toLower model.searchText))
in in
[ viewHeaderBar "Mon coffre" model [ viewHeaderBar "Mon coffre" model
, viewPlayerBar model.state.player renderControls , viewPlayerBar model.state.player renderControls ( model.state.editWealth, model.state.wealthAmount )
, main_ , main_
[ class "container" ] [ class "container" ]
[ viewNotification model [ viewNotification model
@@ -860,6 +879,10 @@ type Msg
| AddMsg AddMsg | AddMsg AddMsg
-- Buy/Sell modes -- Buy/Sell modes
| PriceModifierChanged Int String | PriceModifierChanged Int String
-- Edit wealth
| EditWealth
| AmountChanged String
| ConfirmEditWealth
insensitiveContains : String -> String -> Bool insensitiveContains : String -> String -> Bool
@@ -867,9 +890,42 @@ insensitiveContains substring string =
String.contains (String.toLower substring) (String.toLower string) String.contains (String.toLower substring) (String.toLower string)
switchEditWealth state =
{ state | editWealth = not state.editWealth }
setWealthAmount state amount =
{ state
| wealthAmount = amount
}
update : Msg -> Model -> ( Model, Cmd Msg ) update : Msg -> Model -> ( Model, Cmd Msg )
update msg model = update msg model =
case msg of case msg of
EditWealth ->
( { model | state = switchEditWealth model.state }, Cmd.none )
AmountChanged amount ->
( { model | state = setWealthAmount model.state amount }, Cmd.none )
ConfirmEditWealth ->
let
amount =
case String.toFloat model.state.wealthAmount of
Just a ->
a
Nothing ->
0.0
in
( { model | state = setWealthAmount model.state "0" |> switchEditWealth }
, Cmd.map ApiMsg <|
Api.confirmAction
(String.fromInt model.state.player.id)
(Api.WealthPayload amount)
)
PriceModifierChanged id value -> PriceModifierChanged id value ->
let let
state = state =