summaryrefslogtreecommitdiff
path: root/elm3/RelEdit/Vn.elm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-07-25 14:30:04 +0200
committerYorhel <git@yorhel.nl>2019-07-25 14:36:21 +0200
commitf296495a912ce759df11c43e78b4552788bdbff2 (patch)
tree0c10802de65fb7c8475722e12234bff5eb980628 /elm3/RelEdit/Vn.elm
parent0f3cfeb85caec6424bcbea47142eefbf8011636b (diff)
Merge the v3 branch into separate namespace + fix Docker stuff (again)
I was getting tired of having to keep two branches up-to-date with the latest developments, so decided to throw v3 into the same branch - just different files (...which will get mostly rewritten again soon). The two versions aren't very different in terms of dependencies, build system and support code, so they can now properly share files. Added a section to the README to avoid confusion. This merge also makes it easier to quickly switch between the different versions, which is handy for development. It's even possible to run both at the same time, but my scripts use the same port so that needs a workaround. And it's amazing how often I break the Docker scripts.
Diffstat (limited to 'elm3/RelEdit/Vn.elm')
-rw-r--r--elm3/RelEdit/Vn.elm78
1 files changed, 78 insertions, 0 deletions
diff --git a/elm3/RelEdit/Vn.elm b/elm3/RelEdit/Vn.elm
new file mode 100644
index 00000000..35afb932
--- /dev/null
+++ b/elm3/RelEdit/Vn.elm
@@ -0,0 +1,78 @@
+module RelEdit.Vn exposing (Model, Msg, init, update, view)
+
+import Html exposing (..)
+import Html.Attributes exposing (..)
+import Lib.Html exposing (..)
+import Lib.Gen exposing (RelEditVn)
+import Lib.Util exposing (..)
+import Lib.Autocomplete as A
+import Lib.Api exposing (VN)
+
+
+type alias Model =
+ { vn : List RelEditVn
+ , search : A.Model VN
+ , duplicates : Bool
+ }
+
+
+init : List RelEditVn -> Model
+init l =
+ { vn = l
+ , search = A.init
+ , duplicates = False
+ }
+
+
+type Msg
+ = Del Int
+ | Search (A.Msg VN)
+
+
+searchConfig : A.Config Msg VN
+searchConfig = { wrap = Search, id = "add-vn", source = A.vnSource }
+
+
+validate : Model -> Model
+validate model = { model | duplicates = hasDuplicates <| List.map .vid model.vn }
+
+
+update : Msg -> Model -> (Model, Cmd Msg)
+update msg model =
+ case msg of
+ Del i -> (validate { model | vn = delidx i model.vn }, Cmd.none)
+ Search m ->
+ let (nm, c, res) = A.update searchConfig m model.search
+ in case res of
+ Nothing -> ({ model | search = nm }, c)
+ Just r ->
+ let nrow = { vid = r.id, title = r.title }
+ in (validate { model | search = A.clear nm, vn = model.vn ++ [nrow] }, c)
+
+
+view : Model -> Html Msg
+view model =
+ let
+ entry n e = editListRow "row--ai-center"
+ [ editListField 1 "col-form-label single-line"
+ [ a [href <| "/v" ++ String.fromInt e.vid, title e.title, target "_blank" ] [text e.title ] ]
+ , editListField 0 "" [ removeButton (Del n) ]
+ ]
+
+ in cardRow "Visual Novels" Nothing
+ <| editList (List.indexedMap entry model.vn)
+ ++ formGroups (
+ (if model.duplicates
+ then [ [ div [ class "invalid-feedback" ]
+ [ text "The list contains duplicates. Make sure that the same visual novel is not listed multiple times." ] ] ]
+ else []
+ ) ++
+ (if List.isEmpty model.vn
+ then [ [ div [ class "invalid-feedback" ]
+ [ text "Please make sure that at least one visual novel is selected." ] ] ]
+ else []
+ ) ++
+ [ label [for "add-vn"] [text "Add visual novel"]
+ :: A.view searchConfig model.search [placeholder "Visual Novel...", style "max-width" "400px"]
+ ]
+ )