@@ -41,60 +41,49 @@ const translate = (str, locale = "en") => {
4141 return newStr ?newStr :str
4242}
4343
44+ const Content = ( props ) => {
45+ const [ showContentEnabled , setShowContentEnabled ] = React . useState ( false ) ;
4446
45- class Content extends React . Component {
46- constructor ( props ) {
47- super ( props ) ;
48- this . state = { showContentEnabled : false }
49-
50- }
51-
52- componentDidMount ( ) {
53- if ( this . props . onLoad ) {
54- this . props . onLoad ( )
47+ React . useEffect ( ( ) => {
48+ if ( props . onLoad ) {
49+ props . onLoad ( ) ;
5550 }
56- }
57-
58- componentDidUpdate ( prevProps , prevState , snapshot ) {
59- }
51+ } , [ ] ) ;
6052
61- render ( ) {
62- const {
63- post, pageNumber, showTitle, showContent, showIntro, showDate, showLoading, as, locale, messages, preview
64- } = this . props
53+ const {
54+ post, pageNumber, showTitle, showContent, showIntro, showDate, showLoading, as, locale, messages, preview
55+ } = props ;
6556
66- if ( post ) {
67- const contentParts = post . content ? post . content . rendered . split ( "<!--more-->" ) : [ ]
68- const intro = contentParts . length > 1 ? contentParts [ 0 ] : null
69- const content = contentParts . length > 1 ? contentParts [ 1 ] : contentParts [ 0 ]
70- const pages = content ? content . split ( "<!--nextpage-->" ) : '' ;
57+ if ( post ) {
58+ const contentParts = post . content ? post . content . rendered . split ( "<!--more-->" ) : [ ]
59+ const intro = contentParts . length > 1 ? contentParts [ 0 ] : null
60+ const content = contentParts . length > 1 ? contentParts [ 1 ] : contentParts [ 0 ]
61+ const pages = content ? content . split ( "<!--nextpage-->" ) : '' ;
7162
72- let body = ''
73- if ( pageNumber != null && pages . length > 0 ) {
74- body = pages [ pageNumber ]
75- } else {
76- body = content
77- }
78-
79- return < EmbeddedGateway parentUnique = { this . props . parentUnique } messages = { messages }
80- parent = { preview ? post . parent : post . id } >
81- < Enhance className = "entry-content" { ...this . props } >
82- < div > </ div >
83- { showDate && < Container fluid className = "date" > { post . date . toLocaleString ( ) } </ Container > }
84- { showTitle && < span id = { post . slug } className = "title"
85- dangerouslySetInnerHTML = { { __html : post . title . rendered } } /> }
86- { showIntro && < Container fluid className = "excerpt"
87- dangerouslySetInnerHTML = { { __html : removePatternBrackets ( replaceHTMLinks ( translate ( intro , locale ) , locale ) ) } } /> }
88- { showContent && < Container fluid className = "content "
89- dangerouslySetInnerHTML = { { __html : removePatternBrackets ( replaceHTMLinks ( translate ( body , locale ) , locale ) ) } } /> }
90-
91- </ Enhance >
92- </ EmbeddedGateway >
63+ let body = ''
64+ if ( pageNumber != null && pages . length > 0 ) {
65+ body = pages [ pageNumber ]
9366 } else {
94- return showLoading ? 'Loading' : false ;
67+ body = content
9568 }
96- }
9769
70+ return < EmbeddedGateway parentUnique = { props . parentUnique } messages = { messages }
71+ parent = { preview ? post . parent : post . id } >
72+ < Enhance className = "entry-content" { ...props } >
73+ < div > </ div >
74+ { showDate && < Container fluid className = "date" > { post . date . toLocaleString ( ) } </ Container > }
75+ { showTitle && < span id = { post . slug } className = "title"
76+ dangerouslySetInnerHTML = { { __html : post . title . rendered } } key = "title" /> }
77+ { showIntro && < Container fluid className = "excerpt"
78+ dangerouslySetInnerHTML = { { __html : removePatternBrackets ( replaceHTMLinks ( translate ( intro , locale ) , locale ) ) } } key = "intro" /> }
79+ { showContent && < Container fluid className = "content "
80+ dangerouslySetInnerHTML = { { __html : removePatternBrackets ( replaceHTMLinks ( translate ( body , locale ) , locale ) ) } } key = "content" /> }
81+
82+ </ Enhance >
83+ </ EmbeddedGateway >
84+ } else {
85+ return showLoading ? 'Loading' : false ;
86+ }
9887}
9988
10089
0 commit comments