moves last server API logic inside its own module
This commit is contained in:
36
src/Main.elm
36
src/Main.elm
@@ -205,8 +205,18 @@ update msg model =
|
||||
case model.state.activeMode of
|
||||
Nothing ->
|
||||
update (ModeSwitched Nothing) model
|
||||
|
||||
Just mode ->
|
||||
(model, Cmd.map ApiMsg <| Api.sendRequest mode (String.fromInt model.player.id) (buildPayload mode model))
|
||||
let items = targetItemsFor mode model
|
||||
|> List.filter (itemInSelection model.state.selection)
|
||||
in
|
||||
( model
|
||||
, Cmd.map ApiMsg
|
||||
<| Api.sendRequest
|
||||
mode
|
||||
(String.fromInt model.player.id)
|
||||
items
|
||||
)
|
||||
|
||||
UndoLastAction ->
|
||||
(model, Cmd.map ApiMsg <| Api.undoLastAction model.player.id)
|
||||
@@ -226,30 +236,6 @@ targetItemsFor mode model =
|
||||
Modes.Sell ->Maybe.withDefault [] model.loot
|
||||
Modes.Grab -> Maybe.withDefault [] model.groupLoot
|
||||
|
||||
buildPayload : ViewMode -> Model -> E.Value
|
||||
buildPayload mode model =
|
||||
let
|
||||
items = targetItemsFor mode model
|
||||
|> List.filter (itemInSelection model.state.selection)
|
||||
in
|
||||
case mode of
|
||||
Modes.Buy -> E.object
|
||||
[ ( "items", items |> E.list (\i -> E.list identity [E.int i.id, E.null]))
|
||||
, ("global_mod", E.null )
|
||||
]
|
||||
Modes.Sell -> E.object
|
||||
[ ( "items", items |> E.list (\i -> E.list identity [E.int i.id, E.null]))
|
||||
, ("global_mod", E.null )
|
||||
]
|
||||
Modes.Grab -> E.object
|
||||
[ ( "items", items |> E.list (\i -> E.int i.id))
|
||||
, ("global_mod", E.null )
|
||||
]
|
||||
Modes.Add -> E.object
|
||||
[ ( "items", items |> E.list (\i -> E.int i.id))
|
||||
, ("global_mod", E.null )
|
||||
]
|
||||
|
||||
-- DbUpdates always refer to the active player's loot
|
||||
applyUpdate : Api.Update -> Model -> Model
|
||||
applyUpdate u model =
|
||||
|
||||
Reference in New Issue
Block a user