adds admin, pratices ELM refactoring with 'wealth'

This commit is contained in:
2019-11-21 12:11:33 +01:00
parent 27d7ca63b1
commit 75968f73c1
5 changed files with 234 additions and 101 deletions

View File

@@ -7,6 +7,7 @@ import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Json.Encode as E
import Page.Admin as Admin
import Page.Chest as Chest exposing (Msg)
import Route exposing (..)
import Session exposing (..)
@@ -54,7 +55,7 @@ initNavbar key =
type Page
= Chest Chest.Model
-- | Admin Admin.Model
| Admin Admin.Model
| About
| Loading
@@ -115,8 +116,9 @@ viewPage page =
Chest chest ->
( "Loot-a-lot", List.map (Html.map GotChestMsg) (Chest.view chest) )
-- Admin admin ->
-- ("Administration", Admin.view admin)
Admin admin ->
( "Administration", Admin.view admin )
About ->
( "A propos", [ p [] [ text "A propos" ] ] )
@@ -128,6 +130,9 @@ viewPage page =
Chest chest ->
chest.state.player.name
Admin _ ->
"Administration"
About ->
"Loot-a-lot"
@@ -200,6 +205,7 @@ type Msg
| SessionLoaded (Maybe Session)
| SwitchMenuOpen
| GotChestMsg Chest.Msg
| GotAdminMsg Admin.Msg
@@ -226,10 +232,26 @@ update msg model =
case session of
Just logged ->
let
( chest, cmd ) =
Chest.init logged
navKey =
Session.key logged
user =
Session.user logged
in
( model |> setPage (Chest chest), Cmd.map GotChestMsg cmd )
case user of
Session.Player playerId ->
let
( chest, cmd ) =
Chest.init navKey playerId
in
( model |> setPage (Chest chest), Cmd.map GotChestMsg cmd )
Session.Admin ->
let
( admin, cmd ) =
Admin.init navKey
in
( model |> setPage (Admin admin), Cmd.map GotAdminMsg cmd )
Nothing ->
( model |> setPage About, Cmd.none )
@@ -262,6 +284,9 @@ update msg model =
GotChestMsg chestMsg ->
updateChest chestMsg
GotAdminMsg adminMsg ->
( model, Cmd.none )
SwitchMenuOpen ->
( { model | navbar = Navbar (not model.navbar.menuOpen) model.navbar.navKey }, Cmd.none )