refactoring with one page per route (wip)
This commit is contained in:
64
src/Page/GroupChest.elm
Normal file
64
src/Page/GroupChest.elm
Normal 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 )
|
||||
Reference in New Issue
Block a user