works on claims
This commit is contained in:
20
src/Api.elm
20
src/Api.elm
@@ -14,7 +14,7 @@ module Api exposing
|
||||
, blankPlayer
|
||||
, checkList
|
||||
, confirmAction
|
||||
, fetchClaims
|
||||
, fetchClaimsOf
|
||||
, fetchLoot
|
||||
, fetchPlayer
|
||||
)
|
||||
@@ -116,10 +116,20 @@ claimDecoder =
|
||||
(D.field "loot_id" int)
|
||||
|
||||
|
||||
fetchClaims : (Result Http.Error Claims -> msg) -> Int -> Cmd msg
|
||||
fetchClaims toMsg playerId =
|
||||
fetchClaimsOf : (Result Http.Error Claims -> msg) -> Int -> Cmd msg
|
||||
fetchClaimsOf toMsg playerId =
|
||||
let
|
||||
url =
|
||||
case playerId of
|
||||
-- The 'group' need to see all claims
|
||||
0 ->
|
||||
"http://localhost:8088/api/claims"
|
||||
|
||||
id ->
|
||||
"http://localhost:8088/api/players/" ++ String.fromInt playerId ++ "/claims"
|
||||
in
|
||||
Http.get
|
||||
{ url = "http://localhost:8088/api/claims" -- TODO: ++ playerId
|
||||
{ url = url
|
||||
, expect =
|
||||
valueDecoder (D.list claimDecoder)
|
||||
|> Http.expectJson toMsg
|
||||
@@ -197,7 +207,7 @@ fetchLoot toMsg dest =
|
||||
"http://localhost:8088/api/players/" ++ String.fromInt id ++ "/loot"
|
||||
|
||||
OfShop ->
|
||||
"http://localhost:8088/api/items"
|
||||
"http://localhost:8088/api/shop"
|
||||
|
||||
OfGroup ->
|
||||
"http://localhost:8088/api/players/0/loot"
|
||||
|
||||
@@ -42,6 +42,7 @@ type alias State =
|
||||
, sourceName : Maybe String
|
||||
, itemList : Maybe (List String)
|
||||
|
||||
-- , inventoryItems : Loot
|
||||
-- Fetched on init
|
||||
, player : Api.Player
|
||||
, playerLoot : Loot
|
||||
@@ -91,7 +92,7 @@ init (Player navKey playerId) =
|
||||
[]
|
||||
, Cmd.batch
|
||||
[ Api.fetchPlayer GotPlayer playerId
|
||||
, Api.fetchClaims GotClaims playerId
|
||||
, Api.fetchClaimsOf GotClaims playerId
|
||||
, Api.fetchLoot GotLoot (Api.OfPlayer playerId)
|
||||
, Api.fetchLoot GotLoot Api.OfGroup
|
||||
, Api.fetchLoot GotLoot Api.OfShop
|
||||
@@ -233,12 +234,11 @@ viewPlayerBar player actionControls =
|
||||
([ div [ class "level-item" ]
|
||||
[ p [ class "title is-3" ] [ text player.name ] ]
|
||||
, 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" ] [] ]
|
||||
]
|
||||
]
|
||||
++ viewWealth player.wealth
|
||||
++ [ span [ class "icon has-text-danger" ] [ i [ class "fas fa-tools" ] [] ] ]
|
||||
++ (if player.debt > 0 then
|
||||
[ div [ class "level-item" ]
|
||||
[ p [ class "heading is-size-4 has-text-danger" ]
|
||||
@@ -256,6 +256,12 @@ viewPlayerBar player actionControls =
|
||||
]
|
||||
|
||||
|
||||
viewUpdateWealth =
|
||||
[ input [ class "level-item" ] []
|
||||
, button [ class "level-item button" ] [ text "Ok" ]
|
||||
]
|
||||
|
||||
|
||||
viewWealth : Wealth -> List (Html Msg)
|
||||
viewWealth wealth =
|
||||
[ showWealthField "pp" <| String.fromInt wealth.pp
|
||||
@@ -315,9 +321,27 @@ view model =
|
||||
rowRenderer item =
|
||||
case model.state.mode of
|
||||
View ->
|
||||
case model.shown of
|
||||
-- Claim controls for Group chest
|
||||
GroupLoot ->
|
||||
case ( model.state.player.id, model.shown ) of
|
||||
( 0, PlayerLoot ) ->
|
||||
-- The group is viewing its chest
|
||||
let
|
||||
isClaimed =
|
||||
itemInClaims model.claims
|
||||
in
|
||||
case isClaimed item of
|
||||
True ->
|
||||
[ renderIcon
|
||||
{ icon = "fas fa-praying-hands"
|
||||
, size = "small"
|
||||
, ratio = "1x"
|
||||
}
|
||||
]
|
||||
|
||||
False ->
|
||||
[]
|
||||
|
||||
( _, GroupLoot ) ->
|
||||
-- A player is viewing group chest
|
||||
let
|
||||
isClaimed =
|
||||
itemInClaims model.claims
|
||||
@@ -404,7 +428,7 @@ view model =
|
||||
[ class "section" ]
|
||||
(case model.state.mode of
|
||||
Add ->
|
||||
[ viewAddLoot model
|
||||
[ Html.map AddMsg (viewAddLoot model)
|
||||
, viewLoot rowRenderer canSelect isSelected shownItems
|
||||
]
|
||||
|
||||
@@ -571,7 +595,7 @@ fromListModal isActive itemList =
|
||||
]
|
||||
|
||||
|
||||
viewCompletionDropdown : Bool -> Loot -> Html Msg
|
||||
viewCompletionDropdown : Bool -> Loot -> Html AddMsg
|
||||
viewCompletionDropdown shown results =
|
||||
div
|
||||
[ class "dropdown"
|
||||
@@ -593,7 +617,7 @@ viewCompletionDropdown shown results =
|
||||
]
|
||||
|
||||
|
||||
viewAddLoot : Model -> Html Msg
|
||||
viewAddLoot : Model -> Html AddMsg
|
||||
viewAddLoot model =
|
||||
let
|
||||
autoResults =
|
||||
@@ -802,22 +826,8 @@ viewControls mode content =
|
||||
-- UPDATE
|
||||
|
||||
|
||||
type Msg
|
||||
= ApiMsg Api.Msg
|
||||
| ClearNotification
|
||||
| SwitchMenuOpen
|
||||
| SetContent ChestContent
|
||||
| SetSelection (Maybe Selection)
|
||||
| SwitchSelectionState Int
|
||||
| GotLoot Api.ToChest (HttpResult Loot)
|
||||
| GotClaims (HttpResult Claims)
|
||||
| GotPlayer (HttpResult Api.Player)
|
||||
| SearchTextChanged String
|
||||
| ModeSwitched ActionMode
|
||||
| OnModeEnter ActionMode
|
||||
| OnModeExit ActionMode
|
||||
| ConfirmAction
|
||||
| NewItemAdded Item
|
||||
type AddMsg
|
||||
= NewItemAdded Item
|
||||
| NewItemNameChanged String
|
||||
| NewItemPriceChanged String
|
||||
| SourceNameChanged String
|
||||
@@ -826,6 +836,29 @@ type Msg
|
||||
| FromListChanged String
|
||||
| FromListConfirmed
|
||||
| NewItemsFromList Loot (Maybe String)
|
||||
|
||||
|
||||
type Msg
|
||||
= ApiMsg Api.Msg
|
||||
| GotLoot Api.ToChest (HttpResult Loot)
|
||||
| GotClaims (HttpResult Claims)
|
||||
| GotPlayer (HttpResult Api.Player)
|
||||
-- Chest UI
|
||||
| ClearNotification
|
||||
| SwitchMenuOpen
|
||||
| SetContent ChestContent
|
||||
| SearchTextChanged String
|
||||
-- Selection
|
||||
| SetSelection (Maybe Selection)
|
||||
| SwitchSelectionState Int
|
||||
-- Action modes
|
||||
| ModeSwitched ActionMode
|
||||
| OnModeEnter ActionMode
|
||||
| OnModeExit ActionMode
|
||||
| ConfirmAction
|
||||
-- Add loot
|
||||
| AddMsg AddMsg
|
||||
-- Buy/Sell modes
|
||||
| PriceModifierChanged Int String
|
||||
|
||||
|
||||
@@ -870,6 +903,8 @@ update msg model =
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
AddMsg addMsg ->
|
||||
case addMsg of
|
||||
NewItemsFromList newLoot maybeErrors ->
|
||||
let
|
||||
state =
|
||||
@@ -918,7 +953,9 @@ update msg model =
|
||||
itemList =
|
||||
Maybe.withDefault [] model.state.itemList
|
||||
in
|
||||
( { model | state = { state | showModal = False } }, Api.checkList NewItemsFromList itemList )
|
||||
( { model | state = { state | showModal = False } }
|
||||
, Cmd.map AddMsg <| Api.checkList NewItemsFromList itemList
|
||||
)
|
||||
|
||||
OpenModal ->
|
||||
let
|
||||
@@ -962,7 +999,7 @@ update msg model =
|
||||
Nothing ->
|
||||
Item 0 "" newPrice
|
||||
in
|
||||
update (SetNewItem newItem) model
|
||||
update (AddMsg (SetNewItem newItem)) model
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
@@ -984,7 +1021,8 @@ update msg model =
|
||||
in
|
||||
{ model | state = { state | autoComplete = matches } }
|
||||
-- Update newItem field and erase other (outdated) values
|
||||
|> update (SetNewItem <| Item 0 itemName 0)
|
||||
|> update
|
||||
(AddMsg (SetNewItem <| Item 0 itemName 0))
|
||||
|
||||
ApiMsg apiMsg ->
|
||||
case apiMsg of
|
||||
@@ -1051,7 +1089,7 @@ update msg model =
|
||||
model
|
||||
|
||||
OnModeExit mode ->
|
||||
if mode == Add then
|
||||
if mode == Add || mode == Buy then
|
||||
-- Redirect to PlayerLoot view
|
||||
( model, Nav.pushUrl model.navKey "/" )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user