@@ -63,18 +63,22 @@ export default class DiscussionListItem<CustomAttrs extends IDiscussionListItemA
63
63
}
64
64
65
65
view ( ) {
66
- const discussion = this . attrs . discussion ;
66
+ const attrs = this . elementAttrs ( ) ;
67
+
68
+ return < div { ...attrs } > { this . viewItems ( ) . toArray ( ) } </ div > ;
69
+ }
70
+
71
+ viewItems ( ) : ItemList < Mithril . Children > {
72
+ const items = new ItemList < Mithril . Children > ( ) ;
67
73
74
+ const discussion = this . attrs . discussion ;
68
75
const controls = DiscussionControls . controls ( discussion , this ) . toArray ( ) ;
69
- const attrs = this . elementAttrs ( ) ;
70
76
71
- return (
72
- < div { ...attrs } >
73
- { this . controlsView ( controls ) }
74
- { this . slidableUnderneathView ( ) }
75
- { this . contentView ( ) }
76
- </ div >
77
- ) ;
77
+ items . add ( 'controls' , this . controlsView ( controls ) , 100 ) ;
78
+ items . add ( 'slidableUnderneath' , this . slidableUnderneathView ( ) , 90 ) ;
79
+ items . add ( 'content' , this . contentView ( ) , 80 ) ;
80
+
81
+ return items ;
78
82
}
79
83
80
84
controlsView ( controls : Mithril . ChildArray ) : Mithril . Children {
@@ -113,14 +117,22 @@ export default class DiscussionListItem<CustomAttrs extends IDiscussionListItemA
113
117
114
118
return (
115
119
< div className = { classList ( 'DiscussionListItem-content' , 'Slidable-content' , { unread : isUnread , read : isRead } ) } >
116
- { this . authorAvatarView ( ) }
117
- { this . badgesView ( ) }
118
- { this . mainView ( ) }
119
- { this . replyCountItem ( ) }
120
+ { this . contentItems ( ) . toArray ( ) }
120
121
</ div >
121
122
) ;
122
123
}
123
124
125
+ contentItems ( ) : ItemList < Mithril . Children > {
126
+ const items = new ItemList < Mithril . Children > ( ) ;
127
+
128
+ items . add ( 'authorAvatar' , this . authorAvatarView ( ) , 100 ) ;
129
+ items . add ( 'badges' , this . badgesView ( ) , 90 ) ;
130
+ items . add ( 'main' , this . mainView ( ) , 80 ) ;
131
+ items . add ( 'replyCount' , this . replyCountItem ( ) . toArray ( ) , 70 ) ;
132
+
133
+ return items ;
134
+ }
135
+
124
136
authorAvatarView ( ) : Mithril . Children {
125
137
const discussion = this . attrs . discussion ;
126
138
const user = discussion . user ( ) ;
@@ -149,12 +161,22 @@ export default class DiscussionListItem<CustomAttrs extends IDiscussionListItemA
149
161
150
162
return (
151
163
< Link href = { app . route . discussion ( discussion , jumpTo ) } className = "DiscussionListItem-main" >
152
- < h2 className = "DiscussionListItem-title" > { highlight ( discussion . title ( ) , this . highlightRegExp ) } </ h2 >
153
- < ul className = "DiscussionListItem-info" > { listItems ( this . infoItems ( ) . toArray ( ) ) } </ ul >
164
+ { this . mainItems ( ) . toArray ( ) }
154
165
</ Link >
155
166
) ;
156
167
}
157
168
169
+ mainItems ( ) : ItemList < Mithril . Children > {
170
+ const items = new ItemList < Mithril . Children > ( ) ;
171
+
172
+ const discussion = this . attrs . discussion ;
173
+
174
+ items . add ( 'title' , < h2 className = "DiscussionListItem-title" > { highlight ( discussion . title ( ) , this . highlightRegExp ) } </ h2 > , 100 ) ;
175
+ items . add ( 'info' , < ul className = "DiscussionListItem-info" > { listItems ( this . infoItems ( ) . toArray ( ) ) } </ ul > , 90 ) ;
176
+
177
+ return items ;
178
+ }
179
+
158
180
getJumpTo ( ) {
159
181
const discussion = this . attrs . discussion ;
160
182
let jumpTo = 0 ;
@@ -252,30 +274,38 @@ export default class DiscussionListItem<CustomAttrs extends IDiscussionListItemA
252
274
return items ;
253
275
}
254
276
255
- replyCountItem ( ) {
277
+ replyCountItem ( ) : ItemList < Mithril . Children > {
278
+ const items = new ItemList < Mithril . Children > ( ) ;
279
+
256
280
const discussion = this . attrs . discussion ;
257
281
const showUnread = ! this . showRepliesCount ( ) && discussion . isUnread ( ) ;
258
282
259
283
if ( showUnread ) {
260
- return (
284
+ items . add (
285
+ 'unreadCount' ,
261
286
< button className = "Button--ua-reset DiscussionListItem-count" onclick = { this . markAsRead . bind ( this ) } >
262
287
< span aria-hidden = "true" > { abbreviateNumber ( discussion . unreadCount ( ) ) } </ span >
263
288
264
289
< span className = "visually-hidden" >
265
290
{ app . translator . trans ( 'core.forum.discussion_list.unread_replies_a11y_label' , { count : discussion . replyCount ( ) } ) }
266
291
</ span >
267
- </ button >
292
+ </ button > ,
293
+ 100
268
294
) ;
269
- }
295
+ } else {
296
+ items . add (
297
+ 'count' ,
298
+ < span className = "DiscussionListItem-count" >
299
+ < span aria-hidden = "true" > { abbreviateNumber ( discussion . replyCount ( ) ) } </ span >
270
300
271
- return (
272
- < span className = "DiscussionListItem-count" >
273
- < span aria-hidden = "true" > { abbreviateNumber ( discussion . replyCount ( ) ) } </ span >
301
+ < span className = "visually-hidden" >
302
+ { app . translator . trans ( 'core.forum.discussion_list.total_replies_a11y_label' , { count : discussion . replyCount ( ) } ) }
303
+ </ span >
304
+ </ span > ,
305
+ 100
306
+ ) ;
307
+ }
274
308
275
- < span className = "visually-hidden" >
276
- { app . translator . trans ( 'core.forum.discussion_list.total_replies_a11y_label' , { count : discussion . replyCount ( ) } ) }
277
- </ span >
278
- </ span >
279
- ) ;
309
+ return items ;
280
310
}
281
311
}
0 commit comments