works on add from list
This commit is contained in:
@@ -36,6 +36,7 @@ type alias State =
|
||||
, autoComplete : Loot
|
||||
, newItem : Maybe Item
|
||||
, sourceName : Maybe String
|
||||
, itemList : Maybe (List String)
|
||||
|
||||
-- Fetched on init
|
||||
, player : Api.Player
|
||||
@@ -72,6 +73,7 @@ init (Player navKey playerId) =
|
||||
[]
|
||||
Nothing
|
||||
Nothing
|
||||
Nothing
|
||||
Api.blankPlayer
|
||||
[]
|
||||
[]
|
||||
@@ -92,17 +94,28 @@ init (Player navKey playerId) =
|
||||
)
|
||||
|
||||
|
||||
viewNotification : Maybe String -> Html Msg
|
||||
viewNotification notification =
|
||||
case notification of
|
||||
Just t ->
|
||||
div [ class "notification is-success is-marginless" ]
|
||||
[ button [ class "delete", onClick ClearNotification ] []
|
||||
, text t
|
||||
]
|
||||
viewNotification : Model -> Html Msg
|
||||
viewNotification model =
|
||||
div []
|
||||
[ case model.state.notification of
|
||||
Just t ->
|
||||
div [ class "notification is-success" ]
|
||||
[ button [ class "delete", onClick ClearNotification ] []
|
||||
, text t
|
||||
]
|
||||
|
||||
Nothing ->
|
||||
text ""
|
||||
Nothing ->
|
||||
text ""
|
||||
, case model.state.error of
|
||||
Just e ->
|
||||
div [ class "notification is-danger" ]
|
||||
[ button [ class "delete", onClick ClearNotification ] []
|
||||
, text e
|
||||
]
|
||||
|
||||
Nothing ->
|
||||
text ""
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -313,7 +326,7 @@ view model =
|
||||
, viewPlayerBar model.state.player renderControls
|
||||
, main_
|
||||
[ class "container" ]
|
||||
[ viewNotification model.state.notification
|
||||
[ viewNotification model
|
||||
, article
|
||||
[ class "section" ]
|
||||
(case model.state.mode of
|
||||
@@ -470,16 +483,16 @@ viewItemTableRow isSelected canSelect rowRenderer item =
|
||||
--
|
||||
|
||||
|
||||
fromListModal isActive =
|
||||
fromListModal isActive itemList =
|
||||
div [ class "modal", classList [ ( "is-active", isActive ) ] ]
|
||||
[ div [ class "modal-background" ] []
|
||||
, div [ class "modal-card" ]
|
||||
[ header [ class "modal-card-head" ] [ p [ class "modal-card-title" ] [ text "Liste d'objets" ] ]
|
||||
, div [ class "modal-card-body" ]
|
||||
[ textarea [ class "textarea" ] []
|
||||
[ textarea [ class "textarea", value (String.join "\n" itemList), onInput FromListChanged ] []
|
||||
]
|
||||
, div [ class "modal-card-foot" ]
|
||||
[ button [ class "button" ] [ text "Ok" ]
|
||||
[ button [ class "button", onClick FromListConfirmed ] [ text "Ok" ]
|
||||
, button [ class "button" ] [ text "Annuler" ]
|
||||
]
|
||||
]
|
||||
@@ -532,6 +545,14 @@ viewAddLoot model =
|
||||
Nothing ->
|
||||
Item 0 "" 0
|
||||
|
||||
itemList =
|
||||
case model.state.itemList of
|
||||
Just items ->
|
||||
items
|
||||
|
||||
Nothing ->
|
||||
[]
|
||||
|
||||
sourceName =
|
||||
case model.state.sourceName of
|
||||
Just name ->
|
||||
@@ -557,7 +578,7 @@ viewAddLoot model =
|
||||
newItem.id == 0
|
||||
in
|
||||
div [ class "box is-primary" ]
|
||||
[ fromListModal showModal
|
||||
[ fromListModal showModal itemList
|
||||
, div [ class "field is-horizontal" ]
|
||||
[ div [ class "field-label is-medium" ] [ label [ class "label" ] [ text "Source du loot" ] ]
|
||||
, div [ class "field-body" ]
|
||||
@@ -729,6 +750,9 @@ type Msg
|
||||
| SourceNameChanged String
|
||||
| SetNewItem Item
|
||||
| OpenModal
|
||||
| FromListChanged String
|
||||
| FromListConfirmed
|
||||
| NewItemsFromList Loot (Maybe String)
|
||||
|
||||
|
||||
insensitiveContains : String -> String -> Bool
|
||||
@@ -739,6 +763,56 @@ insensitiveContains substring string =
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
NewItemsFromList newLoot maybeErrors ->
|
||||
let
|
||||
state =
|
||||
model.state
|
||||
|
||||
error =
|
||||
case maybeErrors of
|
||||
Just errors ->
|
||||
(String.lines errors
|
||||
|> String.join ""
|
||||
)
|
||||
++ "n'ont pas pu être ajoutés.\n Faites le manuellement !"
|
||||
|> Just
|
||||
|
||||
Nothing ->
|
||||
Nothing
|
||||
in
|
||||
( { model
|
||||
| state =
|
||||
{ state
|
||||
| itemList = Nothing
|
||||
, newLoot = newLoot ++ model.state.newLoot
|
||||
, error = error
|
||||
}
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
FromListChanged newText ->
|
||||
let
|
||||
state =
|
||||
model.state
|
||||
|
||||
itemList =
|
||||
String.lines newText
|
||||
in
|
||||
( { model | state = { state | itemList = Just itemList } }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
FromListConfirmed ->
|
||||
let
|
||||
state =
|
||||
model.state
|
||||
|
||||
itemList =
|
||||
Maybe.withDefault [] model.state.itemList
|
||||
in
|
||||
( { model | state = { state | showModal = False } }, Api.checkList NewItemsFromList itemList )
|
||||
|
||||
OpenModal ->
|
||||
let
|
||||
state =
|
||||
|
||||
Reference in New Issue
Block a user