just triggered an compiler error, marks it

This commit is contained in:
2019-11-27 21:54:54 +01:00
parent 32ff8bd2d6
commit c52fea683d
7 changed files with 87 additions and 62 deletions

View File

@@ -420,6 +420,32 @@ replaceShopItems toMsg loot =
} }
fetchSession toMsg =
let
toSession : Result Http.Error String -> msg
toSession response =
case Debug.log "got session:" response of
Ok value ->
if value == "admin" then
toMsg Nothing
else
case value of
Ok player ->
toMsg <| Just player
Err _ ->
toMsg Nothing
Err _ ->
toMsg Nothing
in
Http.get
{ url = "http://localhost:8088/session"
, expect = Http.expectJson toSession (valueDecoder Api.Player.playerDecoder)
}
-- UTILS -- UTILS

View File

@@ -1,4 +1,4 @@
module Api.Player exposing (Player, Wealth, blankPlayer, get, list, wealthDecoder) module Api.Player exposing (Player, Wealth, blankPlayer, get, list, playerDecoder, wealthDecoder)
import Http import Http
import Json.Decode as D exposing (Decoder, int, string) import Json.Decode as D exposing (Decoder, int, string)

View File

@@ -5,6 +5,7 @@ import Html.Attributes exposing (..)
import Html.Events exposing (..) import Html.Events exposing (..)
import Page.Admin as Admin import Page.Admin as Admin
import Page.Chest as Chest import Page.Chest as Chest
import Page.Chest.Wealth as Wealth
import Page.Shop as Shop import Page.Shop as Shop
import Session exposing (Session) import Session exposing (Session)
import Utils exposing (renderIcon) import Utils exposing (renderIcon)
@@ -83,8 +84,8 @@ view page =
case maybeSession of case maybeSession of
Just session -> Just session ->
case Session.user session of case Session.user session of
Session.Player id -> Session.Player player _ ->
String.fromInt id player.name
Session.Admin -> Session.Admin ->
"Administration" "Administration"
@@ -96,13 +97,13 @@ view page =
case maybeSession of case maybeSession of
Just session -> Just session ->
case Session.user session of case Session.user session of
Session.Player id -> Session.Player player _ ->
let let
linkWithGem = linkWithGem =
navLink "fas fa-gem" navLink "fas fa-gem"
in in
[ navLink "fas fa-store-alt" "Marchand" "/marchand" [ navLink "fas fa-store-alt" "Marchand" "/marchand"
, if id == 0 then , if player.id == 0 then
linkWithGem "Nouveau loot" "/nouveau-tresor" linkWithGem "Nouveau loot" "/nouveau-tresor"
else else
@@ -117,43 +118,52 @@ view page =
in in
( title ( title
, { title = navbarTitle, links = navbarLinks } , { title = navbarTitle, links = navbarLinks }
, viewSessionBar maybeSession controls , [ div [ class "container" ] <|
:: content viewSessionBar maybeSession [ controls ]
:: content
]
) )
viewSessionBar maybeSession controls = viewSessionBar maybeSession controls =
controls let
user =
case Maybe.map Session.user maybeSession of
Nothing ->
[ text "" ]
Just (Session.Player player wealth) ->
Wealth.view player.wealth wealth
++ (if player.debt > 0 then
[ div [ class "level-item" ]
[ p [ class "heading is-size-4 has-text-danger" ]
[ text ("Dette : " ++ String.fromInt player.debt ++ "po") ]
]
]
else
[]
)
|> List.map (Html.map Wealth)
Just Session.Admin ->
[ text "Admin" ]
in
section [ class "hero is-dark is-bold" ]
[ div [ class "hero-body" ]
[ renderLevel user controls ]
]
renderLevel left right =
div [ class "level container is-mobile" ]
[ div [ class "level-left" ] left
, div [ class "level-right" ] right
]
-- PLAYER BAR -- PLAYER BAR
{-
viewPlayerBar : Player -> List (Html Msg) -> Wealth.Model -> Html Msg
viewPlayerBar player actionControls wealthModel =
section [ class "hero is-dark is-bold" ]
[ div [ class "hero-body" ]
[ div [ class "level container is-mobile" ]
[ div [ class "level-left" ]
(Wealth.view player.wealth wealthModel
++ (if player.debt > 0 then
[ div [ class "level-item" ]
[ p [ class "heading is-size-4 has-text-danger" ]
[ text ("Dette : " ++ String.fromInt player.debt ++ "po") ]
]
]
else
[]
)
)
|> Html.map WealthMsg
, div [ class "level-right" ] actionControls
]
]
]
-}
navLink icon linkText url = navLink icon linkText url =
@@ -172,6 +182,7 @@ type PageMsg
= GotChestMsg Chest.Msg = GotChestMsg Chest.Msg
| GotAdminMsg Admin.Msg | GotAdminMsg Admin.Msg
| GotShopMsg Shop.Msg | GotShopMsg Shop.Msg
| Wealth Wealth.Msg
update msg page = update msg page =
@@ -204,7 +215,7 @@ updatePage toPage toMsg ( subModel, subMsg ) =
gotoHome session = gotoHome session =
case Session.user session of case Session.user session of
Session.Player _ -> Session.Player _ _ ->
Chest.init session Chest.init session
|> updatePage Chest GotChestMsg |> updatePage Chest GotChestMsg

View File

@@ -121,8 +121,8 @@ init session =
playerId = playerId =
case Session.user session of case Session.user session of
Session.Player id -> Session.Player player _ ->
id player.id
Session.Admin -> Session.Admin ->
0 0
@@ -148,9 +148,7 @@ init session =
Route.PlayerLoot Route.PlayerLoot
Nothing Nothing
"" ""
(Wealth.init Wealth.init
blankPlayer.wealth
)
[] []
, Cmd.batch , Cmd.batch
[ Api.Player.get GotPlayer playerId [ Api.Player.get GotPlayer playerId

View File

@@ -11,7 +11,7 @@ type Model
| Edit String | Edit String
init wealth = init =
View View

View File

@@ -47,7 +47,7 @@ view model =
Session.Admin -> Session.Admin ->
button [ class "button", onClick IntoRefresh ] [ text "Remplacer" ] button [ class "button", onClick IntoRefresh ] [ text "Remplacer" ]
Session.Player _ -> Session.Player _ _ ->
button [ class "button" ] [ text "Acheter" ] button [ class "button" ] [ text "Acheter" ]
, [ Table.view Table.name loot ] , [ Table.view Table.name loot ]
) )

View File

@@ -1,12 +1,15 @@
module Session exposing (Session, User(..), getSession, init, key, user) module Session exposing (Session, User(..), getSession, init, key, user)
import Api exposing (valueDecoder)
import Api.Player as Player exposing (Player)
import Browser.Navigation as Nav import Browser.Navigation as Nav
import Http import Http
import Json.Decode as D import Json.Decode as D
import Page.Chest.Wealth as Wealth
type User type User
= Player Int = Player Player Wealth.Model
| Admin | Admin
@@ -17,29 +20,16 @@ type Session
init : (Maybe Session -> msg) -> Nav.Key -> Cmd msg init : (Maybe Session -> msg) -> Nav.Key -> Cmd msg
init toMsg navKey = init toMsg navKey =
let let
toSession : Result Http.Error String -> msg toSession : Maybe Player -> msg
toSession response = toSession response =
case Debug.log "got session:" response of case response of
Ok value -> Just player ->
if value == "admin" then toMsg <| Just (Session navKey (Player player Wealth.init))
toMsg <| Just (Session navKey Admin)
else Nothing ->
case String.toInt value of
Just id ->
toMsg <| Just (Session navKey (Player id))
Nothing ->
toMsg
Nothing
Err _ ->
toMsg Nothing toMsg Nothing
in in
Http.get Api.fetchSession toSession
{ url = "http://localhost:8088/session"
, expect = Http.expectJson toSession D.string
}
getSession : { r | session : Session } -> Session getSession : { r | session : Session } -> Session