From b0ac8846fca7869642726672b180b307d4758fa7 Mon Sep 17 00:00:00 2001 From: Artus Date: Sat, 7 Dec 2019 21:51:39 +0100 Subject: [PATCH] fixes bug with notification timeout, adds player selection for group sell --- src/Page.elm | 34 ++++++++----- src/Page/Dashboard.elm | 106 ++++++++++++++++++++++++++++++++++++++--- src/Wealth.elm | 34 ++++++++----- 3 files changed, 142 insertions(+), 32 deletions(-) diff --git a/src/Page.elm b/src/Page.elm index 0cd3239..f03f864 100644 --- a/src/Page.elm +++ b/src/Page.elm @@ -272,18 +272,22 @@ type PageMsg closeAction ( page, cmd ) = - case page of - Home from -> - gotoHome page + let + ( newPage, pageCmd ) = + case page of + Home from -> + gotoHome page - GroupChest from -> - gotoGroupChest page + GroupChest from -> + gotoGroupChest page - Shop from -> - gotoShop page + Shop from -> + 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 diff --git a/src/Page/Dashboard.elm b/src/Page/Dashboard.elm index 3721403..35dfed2 100644 --- a/src/Page/Dashboard.elm +++ b/src/Page/Dashboard.elm @@ -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 ) diff --git a/src/Wealth.elm b/src/Wealth.elm index e5faa82..7d4fc51 100644 --- a/src/Wealth.elm +++ b/src/Wealth.elm @@ -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,21 +42,31 @@ inBarButton = viewUpdateWealth amount = - [ input - [ class "level-item" - , class "input has-text-right has-background-dark has-text-white" - , classList - [ ( "is-danger", (not << isValid) amount ) - , ( "is-success", isValid amount ) + [ div [ class "field level-item has-addons" ] + [ p [ class "control" ] + [ input + [ class "input is-small has-text-right has-background-dark has-text-white" + , classList + [ ( "is-danger", (not << isValid) amount ) + , ( "is-success", isValid amount ) + ] + , value amount + , style "width" "8em" + , onInput AmountChanged + ] + [] ] - , value amount - , style "width" "8em" - , 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