2
2
* PolicyPages component.
3
3
*/
4
4
import _ from 'lodash' ;
5
- import React , { useState } from 'react' ;
5
+ import React , { useState , useEffect } from 'react' ;
6
6
import PT from 'prop-types' ;
7
7
import Sticky from 'react-stickynode' ;
8
- import { config , Link } from 'topcoder-react-utils' ;
8
+ import { config , Link , isomorphy } from 'topcoder-react-utils' ;
9
9
import cn from 'classnames' ;
10
10
import ContentBlock from 'components/Contentful/ContentBlock' ;
11
11
import Error404 from 'components/Error404' ;
@@ -29,6 +29,18 @@ function PolicyPages({
29
29
policies : this === 'policies' , legal : this === 'legal' ,
30
30
} ) ;
31
31
}
32
+ // auto scroll to anchors
33
+ useEffect ( ( ) => {
34
+ if ( isomorphy . isClientSide ( ) ) {
35
+ const { hash } = window . location ;
36
+ setTimeout ( ( ) => {
37
+ const anchor = document . getElementById ( hash ? hash . slice ( 1 ) : null ) ;
38
+ if ( anchor ) {
39
+ anchor . scrollIntoView ( { behavior : 'smooth' , block : 'start' , inline : 'nearest' } ) ;
40
+ }
41
+ } , 5000 ) ;
42
+ }
43
+ } ) ;
32
44
33
45
let { slug } = match . params ;
34
46
const pages = policyData . Policies . concat ( policyData . Legal ) ;
@@ -94,10 +106,6 @@ function PolicyPages({
94
106
) ;
95
107
}
96
108
97
- PolicyPages . defaultProps = {
98
-
99
- } ;
100
-
101
109
PolicyPages . propTypes = {
102
110
match : PT . shape ( ) . isRequired ,
103
111
policyData : PT . shape ( ) . isRequired ,
0 commit comments