fixes bug with notification timeout, adds player selection for group sell

This commit is contained in:
2019-12-07 21:51:39 +01:00
parent 903fdd816d
commit b0ac8846fc
3 changed files with 142 additions and 32 deletions

View File

@@ -272,6 +272,8 @@ type PageMsg
closeAction ( page, cmd ) =
let
( newPage, pageCmd ) =
case page of
Home from ->
gotoHome page
@@ -283,7 +285,9 @@ closeAction ( page, cmd ) =
gotoShop page
_ ->
( page, cmd )
( page, Cmd.none )
in
( newPage, Cmd.batch [ cmd, pageCmd ] )
update msg page =
@@ -342,6 +346,10 @@ update msg page =
)
( CloseNotification _, _, _ ) ->
let
_ =
Debug.log "lost close msg" 0
in
( page, Cmd.none )
-- Wealth viewer/editor
@@ -394,10 +402,10 @@ update msg page =
|> map (Session.updateUser updatedUser)
|> map (Session.updateNotifications ( result.notification, result.errors ))
, case result.notification of
Just _ ->
Process.sleep 5000.0
|> Task.andThen (\_ -> Task.succeed <| CloseNotification NotifySuccess)
|> Task.perform identity
Just n ->
Task.perform
(\_ -> CloseNotification NotifySuccess)
(Process.sleep 5000.0)
Nothing ->
Cmd.none

View File

@@ -42,7 +42,7 @@ type alias NewPlayerForm =
type alias ExtraData =
{ sourceName : String
, players : List Player
, players : List ( Bool, Player )
}
@@ -75,10 +75,18 @@ init session =
Chest.init
, extra = ExtraData "" []
}
, Cmd.none
, if data.player.id == 0 then
fetchPlayers
else
Cmd.none
)
fetchPlayers =
Player.list (PlayerViewer << GotPlayers)
modeButton t msg =
button [ class "button", onClick msg ] [ text t ]
@@ -152,8 +160,12 @@ view model =
_ ->
text ""
, List.map (Html.map PlayerViewer)
[ case config.chest of
Chest.New _ ->
[ let
isGroup =
data.player.id == 0
in
case ( config.chest, isGroup ) of
( Chest.New _, True ) ->
div [ class "field" ]
[ label [ class "label" ] [ text "Source" ]
, input
@@ -165,6 +177,9 @@ view model =
[]
]
( Chest.Sell _, True ) ->
selectPlayers config.extra.players
_ ->
text ""
, Html.map GotChestMsg <| Chest.view config.chest data.loot
@@ -204,6 +219,28 @@ view model =
)
selectPlayers players =
div [ class "field" ] <|
[ label [ class "label" ] [ text "Joueurs qui partagent le butin" ]
, div [ class "tags is-medium" ] <|
List.map
(\( isSelected, player ) ->
label [ class "checkbox tag", classList [ ( "is-success", isSelected ) ] ]
[ input
[ type_ "checkbox"
, checked isSelected
, onClick (SwitchPlayerChecked player.id)
, class "is-hidden"
, disabled (player.id == 0)
]
[]
, text player.name
]
)
players
]
viewPlayer : Player -> Html Msg
viewPlayer player =
tr [] [ td [] [ p [] [ text (player.name ++ " (" ++ String.fromInt player.id ++ ")") ] ] ]
@@ -258,7 +295,10 @@ type PlayerMsg
= GotChestMsg Chest.Msg
| ConfirmSell
| ConfirmAdd
-- Group specific messages
| SourceNameChanged String
| GotPlayers (List Player)
| SwitchPlayerChecked Int
update msg model =
@@ -291,12 +331,15 @@ update msg model =
, Cmd.map Api <|
case Session.user config.session of
Session.Player data ->
-- TODO: handle list of players when Viewer is group
Chest.confirmSell
data.player.id
config.chest
data.loot
[]
<|
-- Extracts id of checked players
List.map
(.id << Tuple.second)
(List.filter Tuple.first config.extra.players)
_ ->
Cmd.none
@@ -329,7 +372,56 @@ update msg model =
extra =
config.extra
in
( Player { config | extra = { extra | sourceName = new } }, Cmd.none )
( Player
{ config
| extra =
{ extra
| sourceName = new
}
}
, Cmd.none
)
GotPlayers players ->
let
extra =
config.extra
in
( Player
{ config
| extra =
{ extra
| players = List.map (\p -> ( True, p )) players
}
}
, Cmd.none
)
SwitchPlayerChecked id ->
let
extra =
config.extra
in
( Player
{ config
| extra =
{ extra
| players =
List.map
(\( isChecked, player ) ->
( if player.id /= id then
isChecked
else
not isChecked
, player
)
)
extra.players
}
}
, Cmd.none
)
_ ->
( model, Cmd.none )

View File

@@ -23,7 +23,7 @@ view wealth model =
:: (case model of
View ->
viewWealth wealth
++ [ div [ class "level-item button is-small is-dark" ]
++ [ div [ inBarButton, class "level-item is-primary" ]
[ span
[ class "icon is-small"
, onClick StartEdit
@@ -42,9 +42,10 @@ inBarButton =
viewUpdateWealth amount =
[ div [ class "field level-item has-addons" ]
[ p [ class "control" ]
[ input
[ class "level-item"
, class "input has-text-right has-background-dark has-text-white"
[ class "input is-small has-text-right has-background-dark has-text-white"
, classList
[ ( "is-danger", (not << isValid) amount )
, ( "is-success", isValid amount )
@@ -54,9 +55,18 @@ viewUpdateWealth amount =
, onInput AmountChanged
]
[]
]
, p [ class "control" ] [ a [ inBarButton, class "is-warning is-static" ] [ text "po" ] ]
]
, button
[ inBarButton
, class "level-item is-primary"
, class "level-item"
, class <|
if isValid amount then
"is-success"
else
"is-danger"
, onClick ConfirmEdit
]
[ B.icon