summaryrefslogtreecommitdiff
path: root/elm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-08-16 14:17:14 +0200
committerYorhel <git@yorhel.nl>2020-08-16 14:17:14 +0200
commit1c23fdb2ef7acebabf069e8bb9a576805d89f1b6 (patch)
treee809a947dc09baec467b132e5a4197f38ef5ea59 /elm
parent35902bbf0150df1710474be3b6618ec73c6c2623 (diff)
reviews: Add comment form
Diffstat (limited to 'elm')
-rw-r--r--elm/Reviews/Comment.elm52
1 files changed, 52 insertions, 0 deletions
diff --git a/elm/Reviews/Comment.elm b/elm/Reviews/Comment.elm
new file mode 100644
index 00000000..fba37168
--- /dev/null
+++ b/elm/Reviews/Comment.elm
@@ -0,0 +1,52 @@
+module Reviews.Comment 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.ReviewsComment as GRC
+
+
+main : Program GRC.Send Model Msg
+main = Browser.element
+ { init = \e -> ((Api.Normal, e.id, TP.bbcode ""), Cmd.none)
+ , view = view
+ , update = update
+ , subscriptions = always Sub.none
+ }
+
+type alias Model = (Api.State, String, TP.Model)
+
+type Msg
+ = Content TP.Msg
+ | Submit
+ | Submitted GApi.Response
+
+
+update : Msg -> Model -> (Model, Cmd Msg)
+update msg (state,id,content) =
+ case msg of
+ Content m -> let (nm,nc) = TP.update m content in ((state,id,nm), Cmd.map Content nc)
+ Submit -> ((Api.Loading,id,content), GRC.send { msg = content.data, id = id } Submitted)
+ Submitted (GApi.Redirect s) -> ((state,id,content), load s)
+ Submitted r -> ((Api.Error r,id,content), Cmd.none)
+
+
+view : Model -> Html Msg
+view (state,_,content) =
+ form_ Submit (state == Api.Loading)
+ [ div [ class "mainbox" ]
+ [ fieldset [ class "submit" ]
+ [ TP.view "msg" content Content 600 ([rows 4, cols 50] ++ GRC.valMsg)
+ [ b [] [ text "Comment" ]
+ , b [ class "standout" ] [ text " (English please!) " ]
+ , a [ href "/d9#3" ] [ text "Formatting" ]
+ ]
+ , submitButton "Submit" state True
+ ]
+ ]
+ ]