@@ -6,17 +6,16 @@ module Tutorial where
66 import Control.Monad.Eff
77 import Data.Array
88 import React
9+ import React.DOM
910 import Showdown
1011 import Debug.Trace
1112
12- import qualified React.DOM as DOM
13-
1413 cBoxRender = do
1514 state <- readState
16- pure $ DOM. div { className : " commentBox" }
17- [ DOM. h1 {} [ DOM. text " Comments" ]
15+ pure $ div [ className " commentBox" ]
16+ [ h1' [ text " Comments" ]
1817 , commentList { data': state }
19- , commentForm { onCommentSubmit : handle commentSubmit }
18+ , commentForm { onCommentSubmit : commentSubmit }
2019 ]
2120
2221 commentBox = mkUI spec {
@@ -34,37 +33,33 @@ module Tutorial where
3433
3534 commentList = mkUI spec do
3635 props <- getProps
37- pure $ DOM. div { className : " commentList" }
36+ pure $ div [ className " commentList" ]
3837 (commentNodes <$> props .data' )
3938
4039 commentForm = mkUI spec do
4140 props <- getProps
42- pure $ DOM. form { className : " commentForm"
43- , onSubmit : handle submit
44- }
45- [ DOM. input { attrType : " text"
46- , placeholder: " Your name"
47- , ref: " author"
48- }
49- []
50- , DOM. input { attrType : " text"
51- , placeholder: " Say something..."
52- , ref: " text"
53- }
54- []
55- , DOM. input { attrType : " submit"
56- , value: " Post"
57- }
58- []
41+ pure $ form [ className " commentForm"
42+ , onSubmit submit
43+ ]
44+ [ input [ typeProp " text"
45+ , placeholder " Your name"
46+ , ref " author"
47+ ] []
48+ , input [ typeProp " text"
49+ , placeholder " Say something..."
50+ , ref " text"
51+ ] []
52+ , input [ typeProp " submit"
53+ , value " Post"
54+ ] []
5955 ]
6056
6157 comment = mkUI spec do
6258 props <- getProps
63- pure $ DOM. div { className : " comment" }
64- [ DOM. h2 { className : " commentAuthor" }
65- [ DOM. text props.author ]
66- , DOM. span { dangerouslySetInnerHTML : { __html: makeHtml props.children } }
67- []
59+ pure $ div [ className " comment" ]
60+ [ h2 [ className " commentAuthor" ]
61+ [ text props.author ]
62+ , span [ dangerouslySetInnerHTML $ makeHtml props.children ] []
6863 ]
6964
7065 commentNodes c = comment { author: c.author, children: c.text }
@@ -86,14 +81,17 @@ module Tutorial where
8681 \}" :: forall eff. Eff eff {}
8782
8883 foreign import submit
89- " function submit() {\
90- \ var author = this.refs.author.getDOMNode().value.trim();\
91- \ var text = this.refs.text.getDOMNode().value.trim();\
92- \ this.props.onCommentSubmit.call(this, {author: author, text: text});\
93- \ this.refs.author.getDOMNode().value = '';\
94- \ this.refs.text.getDOMNode().value = '';\
95- \ return false;\
96- \}" :: forall eff. Eff eff Boolean
84+ " function submit(e) {\
85+ \ e.preventDefault();\
86+ \ return function() { \
87+ \ var author = this.refs.author.getDOMNode().value.trim();\
88+ \ var text = this.refs.text.getDOMNode().value.trim();\
89+ \ this.props.onCommentSubmit.call(this, {author: author, text: text});\
90+ \ this.refs.author.getDOMNode().value = '';\
91+ \ this.refs.text.getDOMNode().value = '';\
92+ \ return false;\
93+ \ } \
94+ \}" :: Event -> forall eff. Eff eff Boolean
9795
9896 foreign import loadCommentsFromServer
9997 " function loadCommentsFromServer() {\
0 commit comments