small tweaks
This commit is contained in:
134
src/Page.elm
134
src/Page.elm
@@ -2,15 +2,17 @@ module Page exposing (Page(..), PageMsg, gotoGroupChest, gotoHome, gotoShop, ini
|
||||
|
||||
import Api
|
||||
import Api.Player
|
||||
import Bulma as B
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (..)
|
||||
import Page.Dashboard as Home
|
||||
import Page.GroupChest as GroupChest
|
||||
import Page.Shop as Shop
|
||||
import Process
|
||||
import Route
|
||||
import Session exposing (Session)
|
||||
import Utils exposing (renderIcon)
|
||||
import Task
|
||||
import Wealth
|
||||
|
||||
|
||||
@@ -49,16 +51,16 @@ maybeSession page =
|
||||
|
||||
view page =
|
||||
let
|
||||
( title, ( controls, content ) ) =
|
||||
( pageTitle, ( controls, content ) ) =
|
||||
case page of
|
||||
Home home ->
|
||||
( "Lootalot"
|
||||
( "Loot-a-lot"
|
||||
, Home.view home
|
||||
|> mapPageMsg GotHomeMsg
|
||||
)
|
||||
|
||||
GroupChest chest ->
|
||||
( "Lootalot"
|
||||
( "Coffre de groupe"
|
||||
, GroupChest.view chest
|
||||
|> mapPageMsg GotGroupChestMsg
|
||||
)
|
||||
@@ -83,42 +85,38 @@ view page =
|
||||
)
|
||||
)
|
||||
|
||||
navbarTitle =
|
||||
( navbarTitle, navbarLinks ) =
|
||||
case maybeSession page of
|
||||
Just session ->
|
||||
case Session.user session of
|
||||
Session.Player data ->
|
||||
data.player.name
|
||||
( data.player.name
|
||||
, [ navLink "fas fa-home" Route.Home page
|
||||
, navLink "fas fa-store-alt" Route.Merchant page
|
||||
, if data.player.id /= 0 then
|
||||
navLink "fas fa-gem" Route.GroupChest page
|
||||
|
||||
else
|
||||
text ""
|
||||
]
|
||||
)
|
||||
|
||||
Session.Admin _ ->
|
||||
"Administration"
|
||||
( "Administration"
|
||||
, [ navLink "fas fa-home" Route.Home page
|
||||
, navLink "fas fa-store-alt" Route.Merchant page
|
||||
]
|
||||
)
|
||||
|
||||
Nothing ->
|
||||
"Loot-a-lot"
|
||||
|
||||
navbarLinks =
|
||||
case maybeSession page of
|
||||
Just session ->
|
||||
case Session.user session of
|
||||
Session.Player data ->
|
||||
[ navLink "fas fa-store-alt" Route.Merchant page
|
||||
, if data.player.id /= 0 then
|
||||
navLink "fas fa-gem" Route.GroupChest page
|
||||
|
||||
else
|
||||
text ""
|
||||
]
|
||||
|
||||
Session.Admin _ ->
|
||||
[ navLink "fas fa-store-alt" Route.Merchant page ]
|
||||
|
||||
Nothing ->
|
||||
[]
|
||||
( "Loot-a-lot"
|
||||
, []
|
||||
)
|
||||
in
|
||||
( title
|
||||
( pageTitle
|
||||
, { title = navbarTitle, links = navbarLinks }
|
||||
, [ div [ class "container" ] <|
|
||||
[ viewSessionBar (maybeSession page) [ controls ]
|
||||
[ viewSessionBar (maybeSession page) pageTitle [ controls ]
|
||||
, div [ class "section" ]
|
||||
content
|
||||
]
|
||||
@@ -141,40 +139,40 @@ viewNotification kind content =
|
||||
NotifyError ->
|
||||
"is-danger"
|
||||
in
|
||||
div [ class "level-item" ]
|
||||
[ span [ class ("tag " ++ className) ]
|
||||
[ text content
|
||||
, a [ class "delete" ] []
|
||||
]
|
||||
div [ class ("level-item notification " ++ className) ]
|
||||
[ text content
|
||||
, a [ class "delete", onClick <| CloseNotification kind ] []
|
||||
]
|
||||
|
||||
|
||||
viewSessionBar session controls =
|
||||
viewSessionBar session pageTitle pageControls =
|
||||
let
|
||||
user =
|
||||
case Maybe.map Session.user session of
|
||||
Nothing ->
|
||||
[ text "" ]
|
||||
[]
|
||||
|
||||
Just (Session.Player data) ->
|
||||
-- TODO: Urgh ! When will this Wealth.Model move out of session !
|
||||
Wealth.view data.player.wealth data.wealth
|
||||
++ (if data.player.debt > 0 then
|
||||
[ div [ class "level-item" ]
|
||||
[ p [ class "has-text-right has-text-danger" ]
|
||||
[ strong [ class "heading is-marginless has-text-danger" ] [ text "Dette" ]
|
||||
, span [ class <| "is-size-4" ] [ text (String.fromInt data.player.debt ++ "po") ]
|
||||
[ div [ class "level-item level is-mobile" ] <|
|
||||
List.map (Html.map Wealth) <|
|
||||
Wealth.view data.player.wealth data.wealth
|
||||
++ (if data.player.debt > 0 then
|
||||
[ div [ class "level-item" ]
|
||||
[ p [ class "has-text-right has-text-danger" ]
|
||||
[ strong [ class "heading is-marginless has-text-danger" ] [ text "Dette" ]
|
||||
, span [ class <| "is-size-4" ] [ text (String.fromInt data.player.debt ++ "po") ]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
else
|
||||
[]
|
||||
)
|
||||
|> List.map (Html.map Wealth)
|
||||
else
|
||||
[]
|
||||
)
|
||||
]
|
||||
|
||||
Just (Session.Admin _) ->
|
||||
[ text "Admin" ]
|
||||
[]
|
||||
|
||||
notifications =
|
||||
[ case Maybe.map Session.notification session of
|
||||
@@ -190,15 +188,20 @@ viewSessionBar session controls =
|
||||
_ ->
|
||||
text ""
|
||||
]
|
||||
|
||||
title =
|
||||
p [ class "title" ] [ text pageTitle ]
|
||||
in
|
||||
section [ class "hero is-dark is-bold" ]
|
||||
[ div [ class "hero-body" ]
|
||||
[ renderLevel user (notifications ++ controls) ]
|
||||
[ renderLevel notifications user
|
||||
, renderLevel [ title ] pageControls
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
renderLevel left right =
|
||||
div [ class "level container is-mobile" ]
|
||||
div [ class "level container" ]
|
||||
[ div [ class "level-left" ] left
|
||||
, div [ class "level-right" ] right
|
||||
]
|
||||
@@ -219,7 +222,7 @@ navLink icon route page =
|
||||
( "Coffre de groupe", "/groupe" )
|
||||
|
||||
Route.Home ->
|
||||
( "Home", "/" )
|
||||
( "Accueil", "/" )
|
||||
|
||||
Route.About ->
|
||||
( "About", "/" )
|
||||
@@ -242,7 +245,7 @@ navLink icon route page =
|
||||
False
|
||||
in
|
||||
a [ class "navbar-item", classList [ ( "is-active", isActive ) ], href url ]
|
||||
[ renderIcon { icon = icon, ratio = "1x", size = "medium" }
|
||||
[ B.icon { icon = icon, ratio = Just "fa-1x", size = Just "is-medium" }
|
||||
, span [] [ text link ]
|
||||
]
|
||||
|
||||
@@ -258,6 +261,7 @@ type PageMsg
|
||||
| GotHomeMsg Home.Msg
|
||||
| GotShopMsg Shop.Msg
|
||||
| Wealth Wealth.Msg
|
||||
| CloseNotification NotificationKind
|
||||
|
||||
|
||||
|
||||
@@ -343,6 +347,21 @@ update msg page =
|
||||
( GotShopMsg _, _, _ ) ->
|
||||
( page, Cmd.none )
|
||||
|
||||
-- Notifications
|
||||
--
|
||||
( CloseNotification kind, _, _ ) ->
|
||||
( map
|
||||
(case kind of
|
||||
NotifySuccess ->
|
||||
Session.setNotification Nothing
|
||||
|
||||
NotifyError ->
|
||||
Session.setError Nothing
|
||||
)
|
||||
page
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
-- Wealth viewer/editor
|
||||
( Wealth wealthMsg, _, Just session ) ->
|
||||
let
|
||||
@@ -392,7 +411,14 @@ update msg page =
|
||||
( page
|
||||
|> map (Session.updateUser updatedUser)
|
||||
|> map (Session.updateNotifications ( result.notification, result.errors ))
|
||||
, Cmd.none
|
||||
, case result.notification of
|
||||
Just _ ->
|
||||
Process.sleep 5000.0
|
||||
|> Task.andThen (\_ -> Task.succeed <| CloseNotification NotifySuccess)
|
||||
|> Task.perform identity
|
||||
|
||||
Nothing ->
|
||||
Cmd.none
|
||||
)
|
||||
|
||||
-- |> setNotification notification
|
||||
|
||||
Reference in New Issue
Block a user