1
- /**
2
- * Login container.
3
- * @module components/theme/Sitemap/Sitemap
4
- */
5
-
6
- import React , { Component } from 'react' ;
1
+ import { useEffect } from 'react' ;
7
2
import PropTypes from 'prop-types' ;
8
3
import { compose } from 'redux' ;
9
4
import { connect } from 'react-redux' ;
10
5
import { asyncConnect } from '@plone/volto/helpers' ;
11
6
import { defineMessages , injectIntl } from 'react-intl' ;
12
- import { Container } from 'semantic-ui-react' ;
7
+ import { Container as SemanticContainer } from 'semantic-ui-react' ;
13
8
import { Helmet , toBackendLang } from '@plone/volto/helpers' ;
14
9
import { Link } from 'react-router-dom' ;
15
10
import config from '@plone/volto/registry' ;
@@ -30,38 +25,26 @@ export function getSitemapPath(pathname = '', lang) {
30
25
}
31
26
32
27
/**
33
- * Sitemap class.
34
- * @class Sitemap
35
- * @extends Component
28
+ * Sitemap function component.
29
+ * @function Sitemap
30
+ * @param {Object } props - Component properties.
31
+ * @returns {JSX.Element } - Rendered component.
36
32
*/
37
- class Sitemap extends Component {
38
- /**
39
- * Property types.
40
- * @property {Object } propTypes Property types.
41
- * @static
42
- */
43
- static propTypes = {
44
- getNavigation : PropTypes . func . isRequired ,
45
- } ;
33
+ function Sitemap ( props ) {
34
+ const {
35
+ location : { pathname } ,
36
+ language,
37
+ getNavigation,
38
+ } = props ;
46
39
47
- componentDidMount ( ) {
40
+ useEffect ( ( ) => {
48
41
const { settings } = config ;
42
+ const lang = settings . isMultilingual ? `${ toBackendLang ( language ) } ` : null ;
43
+ const path = getSitemapPath ( pathname , lang ) ;
44
+ getNavigation ( path , 4 ) ;
45
+ } , [ pathname , language , getNavigation ] ) ;
49
46
50
- const lang = settings . isMultilingual
51
- ? `${ toBackendLang ( this . props . lang ) } `
52
- : null ;
53
-
54
- const path = getSitemapPath ( this . props . location . pathname , lang ) ;
55
- this . props . getNavigation ( path , 4 ) ;
56
- }
57
-
58
- /**
59
- * Render method.
60
- * @method render
61
- * @returns {string } Markup for the component.
62
- */
63
-
64
- renderItems = ( items ) => {
47
+ const renderItems = ( items ) => {
65
48
return (
66
49
< ul >
67
50
{ items . map ( ( item ) => (
@@ -70,26 +53,35 @@ class Sitemap extends Component {
70
53
className = { item . items ?. length > 0 ? 'with-children' : '' }
71
54
>
72
55
< Link to = { item . url } > { item . title } </ Link >
73
- { item . items && this . renderItems ( item . items ) }
56
+ { item . items && renderItems ( item . items ) }
74
57
</ li >
75
58
) ) }
76
59
</ ul >
77
60
) ;
78
61
} ;
79
- render ( ) {
80
- const { items } = this . props ;
81
- return (
82
- < div id = "page-sitemap" >
83
- < Helmet title = { this . props . intl . formatMessage ( messages . Sitemap ) } />
84
- < Container className = "view-wrapper" >
85
- < h1 > { this . props . intl . formatMessage ( messages . Sitemap ) } </ h1 >
86
- { items && this . renderItems ( items ) }
87
- </ Container >
88
- </ div >
89
- ) ;
90
- }
62
+
63
+ const Container =
64
+ config . getComponent ( { name : 'Container' } ) . component || SemanticContainer ;
65
+
66
+ return (
67
+ < div id = "page-sitemap" >
68
+ < Helmet title = { props . intl . formatMessage ( messages . Sitemap ) } />
69
+ < Container className = "view-wrapper" >
70
+ < h1 > { props . intl . formatMessage ( messages . Sitemap ) } </ h1 >
71
+ { props . items && renderItems ( props . items ) }
72
+ </ Container >
73
+ </ div >
74
+ ) ;
91
75
}
92
76
77
+ Sitemap . propTypes = {
78
+ getNavigation : PropTypes . func . isRequired ,
79
+ location : PropTypes . object . isRequired ,
80
+ intl : PropTypes . object . isRequired ,
81
+ lang : PropTypes . string . isRequired ,
82
+ items : PropTypes . array . isRequired ,
83
+ } ;
84
+
93
85
export const __test__ = compose (
94
86
injectIntl ,
95
87
connect (
@@ -116,14 +108,12 @@ export default compose(
116
108
promise : ( { location, store : { dispatch, getState } } ) => {
117
109
if ( ! __SERVER__ ) return ;
118
110
const { settings } = config ;
119
-
120
111
const path = getSitemapPath (
121
112
location . pathname ,
122
113
settings . isMultilingual
123
114
? toBackendLang ( getState ( ) . intl . locale )
124
115
: null ,
125
116
) ;
126
-
127
117
return dispatch ( getNavigation ( path , 4 ) ) ;
128
118
} ,
129
119
} ,
0 commit comments