@@ -8,53 +8,103 @@ import classnames from 'classnames';
8
8
* WordPress dependencies
9
9
*/
10
10
const { Disabled } = wp . components ;
11
- const { Component, Fragment, RawHTML } = wp . element ;
11
+ const { Component, Fragment } = wp . element ;
12
12
const { decodeEntities } = wp . htmlEntities ;
13
- const { __ , _n, sprintf } = wp . i18n ;
13
+ const { __ , _n } = wp . i18n ;
14
14
15
15
/**
16
16
* Internal dependencies
17
17
*/
18
18
import AvatarImage from '../shared/avatar' ;
19
+ import { ItemTitle , ItemHTMLContent } from '../shared/block-content' ;
20
+ import { tokenSplit , arrayTokenReplace } from '../shared/i18n' ;
21
+ import GridContentLayout from '../shared/grid-layout/block-content' ;
19
22
import './block-content.scss' ;
20
23
24
+ function SpeakerSessions ( { speaker, tracks } ) {
25
+ const sessions = get ( speaker , '_embedded.sessions' , [ ] ) ;
26
+
27
+ let output = ( < Fragment > { null } </ Fragment > ) ;
28
+
29
+ if ( sessions . length ) {
30
+ output = (
31
+ < div className = { classnames ( 'wordcamp-item-meta' , 'wordcamp-speaker-sessions' ) } >
32
+ < h4 className = "wordcamp-speaker-sessions-heading" >
33
+ { _n ( 'Session' , 'Sessions' , sessions . length , 'wordcamporg' ) }
34
+ </ h4 >
35
+
36
+ < ul className = "wordcamp-speaker-sessions-list" >
37
+ { sessions . map ( ( session ) =>
38
+ < li
39
+ key = { session . slug }
40
+ className = "wordcamp-speaker-session-content"
41
+ >
42
+ < Disabled >
43
+ < a
44
+ className = "wordcamp-speaker-session-link"
45
+ href = { session . link }
46
+ >
47
+ { decodeEntities ( session . title . rendered . trim ( ) ) || __ ( '(Untitled)' , 'wordcamporg' ) }
48
+ </ a >
49
+ < span className = "wordcamp-speaker-session-info" >
50
+ { session . session_track . length &&
51
+ arrayTokenReplace (
52
+ /* translators: 1: A date; 2: A time; 3: A location; */
53
+ tokenSplit ( __ ( '%1$s at %2$s in %3$s' , 'wordcamporg' ) ) ,
54
+ decodeEntities ( session . session_date_time . date ) ,
55
+ decodeEntities ( session . session_date_time . time ) ,
56
+ get ( tracks . find ( ( value ) => {
57
+ const [ firstTrackId ] = session . session_track ;
58
+ return parseInt ( value . id ) === firstTrackId ;
59
+ } ) , 'name' )
60
+ )
61
+ }
62
+ { ! session . session_track . length &&
63
+ arrayTokenReplace (
64
+ /* translators: 1: A date; 2: A time; */
65
+ tokenSplit ( __ ( '%1$s at %2$s' , 'wordcamporg' ) , ) ,
66
+ decodeEntities ( session . session_date_time . date ) ,
67
+ decodeEntities ( session . session_date_time . time )
68
+ )
69
+ }
70
+ </ span >
71
+ </ Disabled >
72
+ </ li >
73
+ ) }
74
+ </ ul >
75
+ </ div >
76
+ ) ;
77
+ }
78
+
79
+ return output ;
80
+ }
81
+
21
82
class SpeakersBlockContent extends Component {
22
83
render ( ) {
23
84
const { attributes, speakerPosts, tracks } = this . props ;
24
85
const {
25
- layout, grid_columns, className,
26
86
show_avatars, avatar_size, avatar_align,
27
87
content, excerpt_more, show_session,
28
88
} = attributes ;
29
89
30
- const containerClasses = [
31
- 'wordcamp-speakers-block' ,
32
- 'layout-' + layout ,
33
- className ,
34
- ] ;
35
-
36
- if ( 'grid' === layout ) {
37
- containerClasses . push ( 'grid-columns-' + Number ( grid_columns ) ) ;
38
- }
39
-
40
90
return (
41
- < ul className = { classnames ( containerClasses ) } >
91
+ < GridContentLayout
92
+ { ...this . props }
93
+ >
42
94
{ speakerPosts . map ( ( post ) =>
43
- < li
95
+ < div
44
96
key = { post . slug }
45
97
className = { classnames (
46
98
'wordcamp-speaker' ,
47
99
'wordcamp-speaker-' + decodeEntities ( post . slug ) ,
48
- 'wordcamp-clearfix'
49
100
) }
50
101
>
51
- < h3 className = "wordcamp-speaker-name-heading" >
52
- < Disabled >
53
- < a href = { post . link } >
54
- { decodeEntities ( post . title . rendered . trim ( ) ) || __ ( '(Untitled)' , 'wordcamporg' ) }
55
- </ a >
56
- </ Disabled >
57
- </ h3 >
102
+ < ItemTitle
103
+ className = "wordcamp-speaker-title"
104
+ headingLevel = { 3 }
105
+ title = { post . title . rendered . trim ( ) }
106
+ link = { post . link }
107
+ />
58
108
59
109
{ show_avatars &&
60
110
< div className = { classnames ( 'wordcamp-speaker-avatar-container' , 'align-' + decodeEntities ( avatar_align ) ) } >
@@ -72,83 +122,23 @@ class SpeakersBlockContent extends Component {
72
122
}
73
123
74
124
{ ( 'none' !== content ) &&
75
- < div className = { classnames ( 'wordcamp-speaker-content' , 'wordcamp-speaker-content-' + decodeEntities ( content ) ) } >
76
- { 'full' === content &&
77
- < Disabled >
78
- < RawHTML children = { post . content . rendered . trim ( ) } />
79
- < p className = "wordcamp-speaker-permalink" >
80
- < a href = { post . link } >
81
- { __ ( 'Visit speaker page' , 'wordcamporg' ) }
82
- </ a >
83
- </ p >
84
- </ Disabled >
85
- }
86
- { 'excerpt' === content &&
87
- < Disabled >
88
- < RawHTML children = { post . excerpt . rendered . trim ( ) } />
89
- { excerpt_more &&
90
- < p className = "wordcamp-speaker-permalink" >
91
- < a href = { post . link } >
92
- { __ ( 'Read more' , 'wordcamporg' ) }
93
- </ a >
94
- </ p >
95
- }
96
- </ Disabled >
97
- }
98
- </ div >
125
+ < ItemHTMLContent
126
+ className = { classnames ( 'wordcamp-speaker-content-' + decodeEntities ( content ) ) }
127
+ content = { 'full' === content ? post . content . rendered . trim ( ) : post . excerpt . rendered . trim ( ) }
128
+ link = { ( 'full' === content || excerpt_more ) ? post . link : null }
129
+ linkText = { 'full' === content ? __ ( 'Visit session page' , 'wordcamporg' ) : __ ( 'Read more' , 'wordcamporg' ) }
130
+ />
99
131
}
100
132
101
- { true === show_session && post . _embedded . sessions &&
102
- < Fragment >
103
- < h4 className = "wordcamp-speaker-session-heading" >
104
- { _n ( 'Session' , 'Sessions' , post . _embedded . sessions . length , 'wordcamporg' ) }
105
- </ h4 >
106
-
107
- < ul className = "wordcamp-speaker-session-list" >
108
- { post . _embedded . sessions . map ( ( session ) =>
109
- < li
110
- key = { session . slug }
111
- className = "wordcamp-speaker-session-content"
112
- >
113
- < Disabled >
114
- < a
115
- className = "wordcamp-speaker-session-link"
116
- href = { session . link }
117
- >
118
- { decodeEntities ( session . title . rendered . trim ( ) ) || __ ( '(Untitled)' , 'wordcamporg' ) }
119
- </ a >
120
- < br />
121
- < span className = "wordcamp-speaker-session-info" >
122
- { session . session_track . length &&
123
- sprintf (
124
- /* translators: 1: A date; 2: A time; 3: A location; */
125
- __ ( '%1$s at %2$s in %3$s' , 'wordcamporg' ) ,
126
- session . session_date_time . date ,
127
- session . session_date_time . time ,
128
- get ( tracks . find ( ( value ) => {
129
- const [ firstTrackId ] = session . session_track ;
130
- return parseInt ( value . id ) === firstTrackId ;
131
- } ) , 'name' )
132
- )
133
- }
134
- { ! session . session_track . length &&
135
- sprintf (
136
- /* translators: 1: A date; 2: A time; */
137
- __ ( '%1$s at %2$s' , 'wordcamporg' ) ,
138
- session . session_date_time . date ,
139
- session . session_date_time . time
140
- )
141
- }
142
- </ span >
143
- </ Disabled >
144
- </ li >
145
- ) }
146
- </ ul >
147
- </ Fragment >
133
+ { true === show_session &&
134
+ < SpeakerSessions
135
+ speaker = { post }
136
+ tracks = { tracks }
137
+ />
148
138
}
149
- </ li > ,
139
+ </ div > ,
150
140
) }
151
- </ ul >
141
+ </ GridContentLayout >
152
142
) ;
153
143
}
154
144
}
0 commit comments