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