adds claims for group chest view

This commit is contained in:
2019-12-02 15:58:26 +01:00
parent ecb0cc59a8
commit 976fbe6b4b
10 changed files with 249 additions and 192 deletions

View File

@@ -1,11 +1,12 @@
module Page.GroupChest exposing (Model, Msg(..), init, update, view)
module Page.GroupChest exposing (Model, Msg(..), init, refresh, update, view)
import Api exposing (HttpResult, Loot)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Page.Chest as Chest exposing (Chest)
import Session exposing (Session)
import Session exposing (Session, User(..))
import Set
import Table
@@ -36,8 +37,22 @@ type State
| Loaded Loot
getClaimsFromSession session =
case Session.user session of
Session.Player data ->
if data.player.id /= 0 then
data.claims
-- TODO: The group and admin case should be impossible !
else
[]
Session.Admin ->
[]
init session =
( Model session Loading (View Chest.init), Cmd.map Internal <| Api.fetchLoot GotLoot Api.OfGroup )
( Model session Loading (View <| showClaims (getClaimsFromSession session)), Cmd.map Internal <| Api.fetchLoot GotLoot Api.OfGroup )
view : Model -> ( Html Msg, List (Html Msg) )
@@ -55,30 +70,29 @@ view model =
Loaded loot ->
( Html.map Internal <|
let
( isPlayer, isGroup ) =
case Session.user model.session of
Session.Admin ->
( False, False )
Session.Player data ->
( True, data.player.id == 0 )
in
case model.mode of
View _ ->
case Session.user model.session of
Session.Admin ->
text ""
if isPlayer && not isGroup then
button [ class "button", onClick IntoGrab ] [ text "Demander" ]
Session.Player p _ _ ->
if p.id == 0 then
text ""
else
button [ class "button", onClick IntoGrab ] [ text "Demander" ]
else
text ""
Grab _ ->
case Session.user model.session of
Session.Admin ->
text ""
if isPlayer && not isGroup then
button [ class "button", onClick ConfirmGrab ] [ text "Valider" ]
Session.Player p _ _ ->
if p.id == 0 then
text ""
else
button [ class "button", onClick ConfirmGrab ] [ text "Valider" ]
else
text ""
, [ mapChest (\c -> Chest.view c loot) model.mode
|> Html.map (Internal << GotChestMsg)
]
@@ -98,6 +112,31 @@ type InnerMsg
| ConfirmGrab
showClaims claims =
let
itemClaimed item =
List.any (\c -> c.loot_id == item.id) claims
in
Chest.show
(\item ->
[ p []
[ text <|
(if itemClaimed item then
"C"
else
""
)
++ item.name
]
]
)
refresh model =
{ model | mode = View <| showClaims (getClaimsFromSession model.session) }
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
@@ -106,10 +145,10 @@ update msg model =
Internal ConfirmGrab ->
case ( Session.user model.session, model.loot, model.mode ) of
( Session.Player player _ _, Loaded loot, Grab chest ) ->
( { model | mode = View Chest.init }
( Session.Player data, Loaded loot, Grab chest ) ->
( model
, Chest.confirmGrab
player.id
data.player.id
loot
chest
|> Cmd.map Api
@@ -131,10 +170,19 @@ update msg model =
|> updateChest model
IntoGrab ->
( { model | mode = Grab Chest.initSelection }, Cmd.none )
let
claimedIds =
case Session.user model.session of
Player data ->
List.map .loot_id data.claims
Admin ->
[]
in
( { model | mode = Grab <| Chest.initSelection (Just claimedIds) }, Cmd.none )
IntoView ->
( { model | mode = View Chest.init }, Cmd.none )
( refresh model, Cmd.none )
_ ->
( model, Cmd.none )