works on admin page

This commit is contained in:
2019-11-21 15:57:01 +01:00
parent 75968f73c1
commit a81d184af6
8 changed files with 252 additions and 120 deletions

View File

@@ -1,6 +1,5 @@
module Main exposing (..)
import Api exposing (Claim, Claims, Item, Loot, Player, Wealth)
import Browser
import Browser.Navigation as Nav
import Html exposing (..)
@@ -117,7 +116,7 @@ viewPage page =
( "Loot-a-lot", List.map (Html.map GotChestMsg) (Chest.view chest) )
Admin admin ->
( "Administration", Admin.view admin )
( "Administration", List.map (Html.map GotAdminMsg) (Admin.view admin) )
About ->
( "A propos", [ p [] [ text "A propos" ] ] )
@@ -214,21 +213,8 @@ type Msg
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
let
updateChest chestMsg =
case model.page of
Chest chest ->
let
( newChest, cmd ) =
Chest.update chestMsg chest
in
( setPage (Chest newChest) model, Cmd.map GotChestMsg cmd )
_ ->
( model |> setPage About, Cmd.none )
in
case msg of
SessionLoaded session ->
case ( msg, model.page ) of
( SessionLoaded session, _ ) ->
case session of
Just logged ->
let
@@ -256,7 +242,7 @@ update msg model =
Nothing ->
( model |> setPage About, Cmd.none )
LinkClicked urlRequest ->
( LinkClicked urlRequest, _ ) ->
case model.page of
Chest chestModel ->
case urlRequest of
@@ -269,26 +255,40 @@ update msg model =
_ ->
( model, Cmd.none )
UrlChanged url ->
let
route =
Route.fromUrl url
in
case route of
Just (Route.Home content) ->
updateChest (Chest.SetContent content)
( UrlChanged url, page ) ->
-- Handle routing according to current page
case ( Route.fromUrl url, page ) of
( Just (Route.Home content), Chest _ ) ->
update
(GotChestMsg <| Chest.SetContent content)
model
( Just (Route.Home MerchantLoot), Admin _ ) ->
( model, Cmd.none )
_ ->
( model |> setPage About, Cmd.none )
GotChestMsg chestMsg ->
updateChest chestMsg
( SwitchMenuOpen, _ ) ->
( { model | navbar = Navbar (not model.navbar.menuOpen) model.navbar.navKey }, Cmd.none )
GotAdminMsg adminMsg ->
( GotChestMsg chestMsg, Chest chest ) ->
Chest.update chestMsg chest
|> updatePage Chest GotChestMsg model
( GotAdminMsg adminMsg, Admin adminModel ) ->
Admin.update adminMsg adminModel
|> updatePage Admin GotAdminMsg model
( _, _ ) ->
( model, Cmd.none )
SwitchMenuOpen ->
( { model | navbar = Navbar (not model.navbar.menuOpen) model.navbar.navKey }, Cmd.none )
updatePage : (pageModel -> Page) -> (pageMsg -> Msg) -> Model -> ( pageModel, Cmd pageMsg ) -> ( Model, Cmd Msg )
updatePage toModel toMsg model ( pageModel, pageCmd ) =
( { model | page = toModel pageModel }
, Cmd.map toMsg pageCmd
)