@@ -13,15 +13,12 @@ const ArticleActions = props => {
1313 < NavLink
1414 href = { `editor/${ article . slug } ` }
1515 route = "editor"
16- className = "btn btn-outline-secondary btn-sm"
16+ class = "btn btn-outline-secondary btn-sm"
1717 >
18- < i className = "ion-edit" /> Edit Article
18+ < i class = "ion-edit" /> Edit Article
1919 </ NavLink >
20- < button
21- className = "btn btn-outline-danger btn-sm"
22- onClick = { handleDelete }
23- >
24- < i className = "ion-trash-a" /> Delete Article
20+ < button class = "btn btn-outline-danger btn-sm" onClick = { handleDelete } >
21+ < i class = "ion-trash-a" /> Delete Article
2522 </ button >
2623 </ span >
2724 </ Show >
@@ -31,18 +28,20 @@ const ArticleActions = props => {
3128const ArticleMeta = props => {
3229 const article = props . article ;
3330 return (
34- < div className = "article-meta" >
31+ < div class = "article-meta" >
3532 < NavLink href = { `@${ article . author . username } ` } route = "profile" >
3633 < img src = { article . author . image } alt = "" />
3734 </ NavLink >
3835
39- < div className = "info" >
40- < NavLink href = { `@${ article . author . username } ` } route = "profile" className = "author" >
36+ < div class = "info" >
37+ < NavLink
38+ href = { `@${ article . author . username } ` }
39+ route = "profile"
40+ class = "author"
41+ >
4142 { article . author . username }
4243 </ NavLink >
43- < span className = "date" >
44- { new Date ( article . createdAt ) . toDateString ( ) }
45- </ span >
44+ < span class = "date" > { new Date ( article . createdAt ) . toDateString ( ) } </ span >
4645 </ div >
4746
4847 < ArticleActions
@@ -59,31 +58,32 @@ const Comment = props => {
5958 const show =
6059 props . currentUser && props . currentUser . username === comment . author . username ;
6160 return (
62- < div className = "card" >
63- < div className = "card-block" >
64- < p className = "card-text" > { comment . body } </ p >
61+ < div class = "card" >
62+ < div class = "card-block" >
63+ < p class = "card-text" > { comment . body } </ p >
6564 </ div >
66- < div className = "card-footer" >
67- < NavLink href = { `@ ${ comment . author . username } ` } route = "profile" className = "comment-author" >
68- < img
69- src = { comment . author . image }
70- className = "comment-author-img "
71- alt = ""
72- />
65+ < div class = "card-footer" >
66+ < NavLink
67+ href = { `@ ${ comment . author . username } ` }
68+ route = "profile"
69+ class = "comment-author"
70+ >
71+ < img src = { comment . author . image } class = "comment-author-img" alt = "" />
7372 </ NavLink >
7473
75- < NavLink href = { `@${ comment . author . username } ` } route = "profile" className = "comment-author" >
74+ < NavLink
75+ href = { `@${ comment . author . username } ` }
76+ route = "profile"
77+ class = "comment-author"
78+ >
7679 { comment . author . username }
7780 </ NavLink >
78- < span className = "date-posted" >
81+ < span class = "date-posted" >
7982 { new Date ( comment . createdAt ) . toDateString ( ) }
8083 </ span >
8184 { show && (
82- < span className = "mod-options" >
83- < i
84- className = "ion-trash-a"
85- onClick = { ( ) => props . onDelete ( comment . id ) }
86- />
85+ < span class = "mod-options" >
86+ < i class = "ion-trash-a" onClick = { ( ) => props . onDelete ( comment . id ) } />
8787 </ span >
8888 ) }
8989 </ div >
@@ -92,34 +92,30 @@ const Comment = props => {
9292} ;
9393
9494const CommentInput = props => {
95- const [ CommentsStore ] = useStore ( "comments" ) ,
95+ const [ , { createComment } ] = useStore ( ) ,
9696 [ state , setState ] = createState ( { body : "" } ) ,
9797 handleBodyChange = ev => setState ( { body : ev . target . value } ) ,
98- createComment = ev => {
98+ createCommentHandler = ev => {
9999 ev . preventDefault ( ) ;
100- CommentsStore . createComment ( { body : state . body } ) . then ( ( ) =>
100+ createComment ( { body : state . body } ) . then ( ( ) =>
101101 setState ( { body : "" } )
102102 ) ;
103103 } ;
104104 return (
105- < form className = "card comment-form" onSubmit = { createComment } >
106- < div className = "card-block" >
105+ < form class = "card comment-form" onSubmit = { createCommentHandler } >
106+ < div class = "card-block" >
107107 < textarea
108- className = "form-control"
108+ class = "form-control"
109109 placeholder = "Write a comment..."
110110 value = { state . body }
111- disabled = { CommentsStore . state . isCreatingComment }
111+ disabled = { store . isCreatingComment }
112112 onChange = { handleBodyChange }
113113 rows = "3"
114114 />
115115 </ div >
116- < div className = "card-footer" >
117- < img
118- src = { props . currentUser . image }
119- className = "comment-author-img"
120- alt = ""
121- />
122- < button className = "btn btn-sm btn-primary" type = "submit" >
116+ < div class = "card-footer" >
117+ < img src = { props . currentUser . image } class = "comment-author-img" alt = "" />
118+ < button class = "btn btn-sm btn-primary" type = "submit" >
123119 Post Comment
124120 </ button >
125121 </ div >
@@ -128,7 +124,7 @@ const CommentInput = props => {
128124} ;
129125
130126const CommentContainer = props => (
131- < div className = "col-xs-12 col-md-8 offset-md-2" >
127+ < div class = "col-xs-12 col-md-8 offset-md-2" >
132128 < Show
133129 when = { props . currentUser }
134130 fallback = {
@@ -159,34 +155,28 @@ const CommentContainer = props => (
159155
160156export default props => {
161157 let canModify ;
162- const [ ArticlesStore , CommentsStore , UserStore ] = useStore (
163- "articles" ,
164- "comments" ,
165- "user"
166- ) ,
158+ const [ store , { loadArticle, deleteArticle, deleteComment, loadComments } ] = useStore ( ) ,
167159 slug = props . params [ 0 ] ,
168- article = ( ) => ArticlesStore . state . articlesRegistry [ slug ] ,
160+ article = ( ) => store . articles [ slug ] ,
169161 handleDeleteArticle = slug =>
170- ArticlesStore . deleteArticle ( slug ) . then ( ( ) => {
162+ deleteArticle ( slug ) . then ( ( ) => {
171163 // this.props.history.replace("/")
172- } ) ,
173- handleDeleteComment = id => CommentsStore . deleteComment ( id ) ;
164+ } ) ;
174165
175- ArticlesStore . loadArticle ( slug , { acceptCached : true } ) ;
176- CommentsStore . setArticleSlug ( slug ) ;
177- CommentsStore . loadComments ( ) ;
166+ loadArticle ( slug , { acceptCached : true } ) ;
167+ loadComments ( slug ) ;
178168
179169 return (
180170 < div class = "article-page" >
181171 < Show when = { article ( ) } >
182172 {
183173 ( ( canModify =
184- UserStore . state . currentUser &&
185- UserStore . state . currentUser . username === article . author . username ) ,
174+ store . currentUser &&
175+ store . currentUser . username === article ( ) . author . username ) ,
186176 (
187177 < >
188- < div className = "banner" >
189- < div className = "container" >
178+ < div class = "banner" >
179+ < div class = "container" >
190180 < h1 > { article ( ) . title } </ h1 >
191181 < ArticleMeta
192182 article = { article ( ) }
@@ -197,14 +187,16 @@ export default props => {
197187 </ div >
198188
199189 < div class = "container page" >
200- < div className = "row article-content" >
201- < div className = "col-xs-12" >
202- < div innerHTML = { marked ( article ( ) . body , { sanitize : true } ) } />
190+ < div class = "row article-content" >
191+ < div class = "col-xs-12" >
192+ < div
193+ innerHTML = { marked ( article ( ) . body , { sanitize : true } ) }
194+ />
203195
204- < ul className = "tag-list" >
196+ < ul class = "tag-list" >
205197 { article ( ) . tagList . map ( tag => {
206198 return (
207- < li className = "tag-default tag-pill tag-outline" >
199+ < li class = "tag-default tag-pill tag-outline" >
208200 { tag }
209201 </ li >
210202 ) ;
@@ -225,11 +217,11 @@ export default props => {
225217
226218 < div class = "row" >
227219 < CommentContainer
228- comments = { CommentsStore . state . comments }
229- errors = { CommentsStore . state . commentErrors }
220+ comments = { store . comments }
221+ errors = { store . commentErrors }
230222 slug = { slug }
231- currentUser = { UserStore . state . currentUser }
232- onDelete = { handleDeleteComment }
223+ currentUser = { store . currentUser }
224+ onDelete = { deleteComment }
233225 />
234226 </ div >
235227 </ div >
0 commit comments