refactoring with one page per route (wip)

This commit is contained in:
2019-11-27 16:04:26 +01:00
parent 89b22bb07d
commit 32ff8bd2d6
7 changed files with 353 additions and 228 deletions

64
src/Page/GroupChest.elm Normal file
View File

@@ -0,0 +1,64 @@
module Page.GroupChest exposing (..)
import Api exposing (HttpResult, Loot)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Session exposing (Session)
import Table
type alias Model =
{ session : Session
, state : State
}
type State
= Loading
| LoadError String
| View Loot
init session =
( Model session Loading, Api.fetchLoot GotLoot Api.OfGroup )
view model =
case model.state of
Loading ->
( text ""
, [ p [ class "title" ] [ text "loading..." ] ]
)
LoadError error ->
( text ""
, [ p [ class "has-text-danger" ] [ text <| "Error : " ++ error ] ]
)
View loot ->
( case Session.user model.session of
Session.Admin ->
text ""
Session.Player id ->
if id == 0 then
button [ class "button" ] [ text "Vendre" ]
else
button [ class "button" ] [ text "Demander" ]
, [ Table.view Table.name loot ]
)
type Msg
= GotLoot Api.ToChest (HttpResult Loot)
update msg model =
case msg of
GotLoot _ (Ok loot) ->
( { model | state = View loot }, Cmd.none )
GotLoot _ (Err _) ->
( { model | state = LoadError "Le chargement a échoué" }, Cmd.none )