summaryrefslogtreecommitdiff
path: root/elm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-12-05 19:26:39 +0100
committerYorhel <git@yorhel.nl>2019-12-05 19:27:15 +0100
commit6487d1e89b14a4c85bb47c03fbe4d7e2f37e73d3 (patch)
treecd010ce4994048c379abf6ef256543b63f8c9f3a /elm
parent0c97101f1de3025de06a5f516811b9b7844a2abc (diff)
v2rw: Convert thread reply form to Elm
So we can apply the new preview functionality. I got rid of the "Go advanced" button, because there's really nothing advanced about it.
Diffstat (limited to 'elm')
-rw-r--r--elm/Discussions/Reply.elm68
-rw-r--r--elm/Lib/TextPreview.elm2
2 files changed, 69 insertions, 1 deletions
diff --git a/elm/Discussions/Reply.elm b/elm/Discussions/Reply.elm
new file mode 100644
index 00000000..79278a20
--- /dev/null
+++ b/elm/Discussions/Reply.elm
@@ -0,0 +1,68 @@
+module Discussions.Reply exposing (main)
+
+import Html exposing (..)
+import Html.Attributes exposing (..)
+import Browser
+import Browser.Navigation exposing (load)
+import Lib.Html exposing (..)
+import Lib.TextPreview as TP
+import Lib.Api as Api
+import Gen.Api as GApi
+import Gen.DiscussionsReply as GDR
+
+
+main : Program GDR.Recv Model Msg
+main = Browser.element
+ { init = \e -> (init e, Cmd.none)
+ , view = view
+ , update = update
+ , subscriptions = always Sub.none
+ }
+
+
+type alias Model =
+ { state : Api.State
+ , newurl : String
+ , tid : Int
+ , msg : TP.Model
+ }
+
+
+init : GDR.Recv -> Model
+init d =
+ { state = Api.Normal
+ , newurl = d.newurl
+ , tid = d.tid
+ , msg = TP.bbcode ""
+ }
+
+
+type Msg
+ = Content TP.Msg
+ | Submit
+ | Submitted GApi.Response
+
+
+update : Msg -> Model -> (Model, Cmd Msg)
+update msg model =
+ case msg of
+ Content m -> let (nm,nc) = TP.update m model.msg in ({ model | msg = nm }, Cmd.map Content nc)
+
+ Submit ->
+ let body = GDR.encode { msg = model.msg.data, tid = model.tid }
+ in ({ model | state = Api.Loading }, Api.post "/t/reply.json" body Submitted)
+ Submitted GApi.Success -> (model, load model.newurl)
+ Submitted r -> ({ model | state = Api.Error r }, Cmd.none)
+
+
+view : Model -> Html Msg
+view model =
+ form_ Submit (model.state == Api.Loading)
+ [ div [ class "mainbox" ]
+ [ fieldset [ class "submit" ]
+ [ h2 [] [ text "Quick reply", b [ class "standout" ] [ text " (English please!)" ] ]
+ , TP.view "msg" model.msg Content 600 ([rows 4, cols 50] ++ GDR.valMsg)
+ , submitButton "Submit" model.state True
+ ]
+ ]
+ ]
diff --git a/elm/Lib/TextPreview.elm b/elm/Lib/TextPreview.elm
index 8c9e3287..2d565e5f 100644
--- a/elm/Lib/TextPreview.elm
+++ b/elm/Lib/TextPreview.elm
@@ -74,7 +74,7 @@ view name model cmdmap width attr =
div [ class "textpreview", style "width" (String.fromInt width ++ "px") ]
[ p (class "head" :: (if model.data == "" then [class "invisible"] else []))
[ case model.state of
- Api.Loading -> div [ class "spinner" ] []
+ Api.Loading -> span [ class "spinner" ] []
Api.Error _ -> b [ class "grayedout" ] [ text "Error loading preview. " ]
Api.Normal -> text ""
, if display