just triggered an compiler error, marks it
This commit is contained in:
26
src/Api.elm
26
src/Api.elm
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
59
src/Page.elm
59
src/Page.elm
@@ -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,25 +118,22 @@ view page =
|
|||||||
in
|
in
|
||||||
( title
|
( title
|
||||||
, { title = navbarTitle, links = navbarLinks }
|
, { title = navbarTitle, links = navbarLinks }
|
||||||
, viewSessionBar maybeSession controls
|
, [ div [ class "container" ] <|
|
||||||
|
viewSessionBar maybeSession [ controls ]
|
||||||
:: content
|
:: 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
|
||||||
-- 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
|
++ (if player.debt > 0 then
|
||||||
[ div [ class "level-item" ]
|
[ div [ class "level-item" ]
|
||||||
[ p [ class "heading is-size-4 has-text-danger" ]
|
[ p [ class "heading is-size-4 has-text-danger" ]
|
||||||
@@ -146,14 +144,26 @@ viewSessionBar maybeSession controls =
|
|||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
)
|
|> List.map (Html.map Wealth)
|
||||||
|> Html.map WealthMsg
|
|
||||||
, div [ class "level-right" ] actionControls
|
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
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ type Model
|
|||||||
| Edit String
|
| Edit String
|
||||||
|
|
||||||
|
|
||||||
init wealth =
|
init =
|
||||||
View
|
View
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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 ]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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
|
|
||||||
case String.toInt value of
|
|
||||||
Just id ->
|
|
||||||
toMsg <| Just (Session navKey (Player id))
|
|
||||||
|
|
||||||
Nothing ->
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user