fixes bug with notification timeout, adds player selection for group sell
This commit is contained in:
18
src/Page.elm
18
src/Page.elm
@@ -272,6 +272,8 @@ type PageMsg
|
|||||||
|
|
||||||
|
|
||||||
closeAction ( page, cmd ) =
|
closeAction ( page, cmd ) =
|
||||||
|
let
|
||||||
|
( newPage, pageCmd ) =
|
||||||
case page of
|
case page of
|
||||||
Home from ->
|
Home from ->
|
||||||
gotoHome page
|
gotoHome page
|
||||||
@@ -283,7 +285,9 @@ closeAction ( page, cmd ) =
|
|||||||
gotoShop page
|
gotoShop page
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
( page, cmd )
|
( page, Cmd.none )
|
||||||
|
in
|
||||||
|
( newPage, Cmd.batch [ cmd, pageCmd ] )
|
||||||
|
|
||||||
|
|
||||||
update msg page =
|
update msg page =
|
||||||
@@ -342,6 +346,10 @@ update msg page =
|
|||||||
)
|
)
|
||||||
|
|
||||||
( CloseNotification _, _, _ ) ->
|
( CloseNotification _, _, _ ) ->
|
||||||
|
let
|
||||||
|
_ =
|
||||||
|
Debug.log "lost close msg" 0
|
||||||
|
in
|
||||||
( page, Cmd.none )
|
( page, Cmd.none )
|
||||||
|
|
||||||
-- Wealth viewer/editor
|
-- Wealth viewer/editor
|
||||||
@@ -394,10 +402,10 @@ update msg page =
|
|||||||
|> map (Session.updateUser updatedUser)
|
|> map (Session.updateUser updatedUser)
|
||||||
|> map (Session.updateNotifications ( result.notification, result.errors ))
|
|> map (Session.updateNotifications ( result.notification, result.errors ))
|
||||||
, case result.notification of
|
, case result.notification of
|
||||||
Just _ ->
|
Just n ->
|
||||||
Process.sleep 5000.0
|
Task.perform
|
||||||
|> Task.andThen (\_ -> Task.succeed <| CloseNotification NotifySuccess)
|
(\_ -> CloseNotification NotifySuccess)
|
||||||
|> Task.perform identity
|
(Process.sleep 5000.0)
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
Cmd.none
|
Cmd.none
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ type alias NewPlayerForm =
|
|||||||
|
|
||||||
type alias ExtraData =
|
type alias ExtraData =
|
||||||
{ sourceName : String
|
{ sourceName : String
|
||||||
, players : List Player
|
, players : List ( Bool, Player )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -75,10 +75,18 @@ init session =
|
|||||||
Chest.init
|
Chest.init
|
||||||
, extra = ExtraData "" []
|
, extra = ExtraData "" []
|
||||||
}
|
}
|
||||||
, Cmd.none
|
, if data.player.id == 0 then
|
||||||
|
fetchPlayers
|
||||||
|
|
||||||
|
else
|
||||||
|
Cmd.none
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
fetchPlayers =
|
||||||
|
Player.list (PlayerViewer << GotPlayers)
|
||||||
|
|
||||||
|
|
||||||
modeButton t msg =
|
modeButton t msg =
|
||||||
button [ class "button", onClick msg ] [ text t ]
|
button [ class "button", onClick msg ] [ text t ]
|
||||||
|
|
||||||
@@ -152,8 +160,12 @@ view model =
|
|||||||
_ ->
|
_ ->
|
||||||
text ""
|
text ""
|
||||||
, List.map (Html.map PlayerViewer)
|
, List.map (Html.map PlayerViewer)
|
||||||
[ case config.chest of
|
[ let
|
||||||
Chest.New _ ->
|
isGroup =
|
||||||
|
data.player.id == 0
|
||||||
|
in
|
||||||
|
case ( config.chest, isGroup ) of
|
||||||
|
( Chest.New _, True ) ->
|
||||||
div [ class "field" ]
|
div [ class "field" ]
|
||||||
[ label [ class "label" ] [ text "Source" ]
|
[ label [ class "label" ] [ text "Source" ]
|
||||||
, input
|
, input
|
||||||
@@ -165,6 +177,9 @@ view model =
|
|||||||
[]
|
[]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
( Chest.Sell _, True ) ->
|
||||||
|
selectPlayers config.extra.players
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
text ""
|
text ""
|
||||||
, Html.map GotChestMsg <| Chest.view config.chest data.loot
|
, 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 -> Html Msg
|
||||||
viewPlayer player =
|
viewPlayer player =
|
||||||
tr [] [ td [] [ p [] [ text (player.name ++ " (" ++ String.fromInt player.id ++ ")") ] ] ]
|
tr [] [ td [] [ p [] [ text (player.name ++ " (" ++ String.fromInt player.id ++ ")") ] ] ]
|
||||||
@@ -258,7 +295,10 @@ type PlayerMsg
|
|||||||
= GotChestMsg Chest.Msg
|
= GotChestMsg Chest.Msg
|
||||||
| ConfirmSell
|
| ConfirmSell
|
||||||
| ConfirmAdd
|
| ConfirmAdd
|
||||||
|
-- Group specific messages
|
||||||
| SourceNameChanged String
|
| SourceNameChanged String
|
||||||
|
| GotPlayers (List Player)
|
||||||
|
| SwitchPlayerChecked Int
|
||||||
|
|
||||||
|
|
||||||
update msg model =
|
update msg model =
|
||||||
@@ -291,12 +331,15 @@ update msg model =
|
|||||||
, Cmd.map Api <|
|
, Cmd.map Api <|
|
||||||
case Session.user config.session of
|
case Session.user config.session of
|
||||||
Session.Player data ->
|
Session.Player data ->
|
||||||
-- TODO: handle list of players when Viewer is group
|
|
||||||
Chest.confirmSell
|
Chest.confirmSell
|
||||||
data.player.id
|
data.player.id
|
||||||
config.chest
|
config.chest
|
||||||
data.loot
|
data.loot
|
||||||
[]
|
<|
|
||||||
|
-- Extracts id of checked players
|
||||||
|
List.map
|
||||||
|
(.id << Tuple.second)
|
||||||
|
(List.filter Tuple.first config.extra.players)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
Cmd.none
|
Cmd.none
|
||||||
@@ -329,7 +372,56 @@ update msg model =
|
|||||||
extra =
|
extra =
|
||||||
config.extra
|
config.extra
|
||||||
in
|
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 )
|
( model, Cmd.none )
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ view wealth model =
|
|||||||
:: (case model of
|
:: (case model of
|
||||||
View ->
|
View ->
|
||||||
viewWealth wealth
|
viewWealth wealth
|
||||||
++ [ div [ class "level-item button is-small is-dark" ]
|
++ [ div [ inBarButton, class "level-item is-primary" ]
|
||||||
[ span
|
[ span
|
||||||
[ class "icon is-small"
|
[ class "icon is-small"
|
||||||
, onClick StartEdit
|
, onClick StartEdit
|
||||||
@@ -42,9 +42,10 @@ inBarButton =
|
|||||||
|
|
||||||
|
|
||||||
viewUpdateWealth amount =
|
viewUpdateWealth amount =
|
||||||
|
[ div [ class "field level-item has-addons" ]
|
||||||
|
[ p [ class "control" ]
|
||||||
[ input
|
[ input
|
||||||
[ class "level-item"
|
[ class "input is-small has-text-right has-background-dark has-text-white"
|
||||||
, class "input has-text-right has-background-dark has-text-white"
|
|
||||||
, classList
|
, classList
|
||||||
[ ( "is-danger", (not << isValid) amount )
|
[ ( "is-danger", (not << isValid) amount )
|
||||||
, ( "is-success", isValid amount )
|
, ( "is-success", isValid amount )
|
||||||
@@ -54,9 +55,18 @@ viewUpdateWealth amount =
|
|||||||
, onInput AmountChanged
|
, onInput AmountChanged
|
||||||
]
|
]
|
||||||
[]
|
[]
|
||||||
|
]
|
||||||
|
, p [ class "control" ] [ a [ inBarButton, class "is-warning is-static" ] [ text "po" ] ]
|
||||||
|
]
|
||||||
, button
|
, button
|
||||||
[ inBarButton
|
[ inBarButton
|
||||||
, class "level-item is-primary"
|
, class "level-item"
|
||||||
|
, class <|
|
||||||
|
if isValid amount then
|
||||||
|
"is-success"
|
||||||
|
|
||||||
|
else
|
||||||
|
"is-danger"
|
||||||
, onClick ConfirmEdit
|
, onClick ConfirmEdit
|
||||||
]
|
]
|
||||||
[ B.icon
|
[ B.icon
|
||||||
|
|||||||
Reference in New Issue
Block a user