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

View File

@@ -17,6 +17,7 @@ import Html.Attributes exposing (..)
import Html.Events exposing (onCheck, onClick, onInput)
import Page.Chest.Wealth as Wealth
import Route exposing (ChestContent(..))
import Session exposing (Session)
import Set exposing (Set)
import Utils exposing (..)
@@ -28,89 +29,7 @@ setContent content model =
-- MODEL
{-
type alias ViewConfig =
{ filterText : String
}
type alias Selection data =
{ selection : Set Int -- Set of selected items
, selectionData : Dict Int data -- Data associated by id
}
type alias AddConfig =
{ showModal : Bool
, autoComplete : Loot
, newItem : Maybe Item
, sourceName : Maybe String
, itemList : Maybe (List String)
}
type ChestMsg
= ConfirmAction
| CancelAction
| EnterMode ActionMode
| ViewMsg
| SelectionMsg
| AddMsg
type Content
= PlayerLoot Int
| GroupLoot
| MerchantShop
| Inventory
type Context
= View String
| Sell (Selection Int)
| Buy (Selection Int)
| Grab (Selection ())
| Add AddConfig
type Chest
= Chest Context Loot
type Chest
= View ViewConfig Loot
| Sell Selection Loot
| Buy Selection Loot
| Grab Selection Loot
| Add AddConfig Loot
type alias Cache =
{ playerLoot : ...
, ...
, claims : Claims
}
-- Leading to new model
type alias Model =
{ navKey: Nav.Key
, error : Maybe String
, notification : Maybe String
, player : Player
, wealth : Wealth.Model
, cache : Cache
, chest : Chest
}
-- Hence,
type ViewMsg
= SetContent ChestContent
| SearchTextChanged String
type AddMsg
= NewItemAdded Item
| NewItemNameChanged String
@@ -180,7 +99,7 @@ type alias Selection =
type alias Model =
{ navKey : Nav.Key
{ session : Session
, state : State
-- Chest
@@ -194,9 +113,22 @@ type alias Model =
}
init navKey playerId =
init : Session -> ( Model, Cmd Msg )
init session =
let
navKey =
Session.key session
playerId =
case Session.user session of
Session.Player id ->
id
Session.Admin ->
0
in
( Model
navKey
session
(State
View
Nothing
@@ -1119,7 +1051,7 @@ update msg model =
OnModeExit mode ->
if mode == Add || mode == Buy then
-- Redirect to PlayerLoot view
( model, Nav.pushUrl model.navKey "/" )
( model, Nav.pushUrl (Session.key model.session) "/" )
else
( model, Cmd.none )