1
1
import React from 'react' ;
2
2
import Layout from '@theme/Layout' ;
3
- import { useHistory , useLocation } from '@docusaurus/router' ;
3
+ import { useHistory , useLocation } from '@docusaurus/router' ;
4
+ import { useEffect } from 'react' ;
4
5
import { Route } from 'react-router-dom' ;
5
6
import { About } from '@site/src/components/about'
6
7
import LargePortraitCard from '@site/src/components/about/LargePortraitCard' ;
7
8
import { getTeamByPersonName } from '@site/src/components/about' ;
8
9
import styles from "@site/src/components/about/styles.module.css" ;
9
10
11
+
12
+
10
13
export default function LargePortraitCardPage ( ) {
11
14
const location = useLocation ( ) ;
12
15
const history = useHistory ( ) ;
13
16
14
- function handleClose ( ) {
17
+ useEffect ( ( ) => {
15
18
if ( location . state ?. fromAbout ) {
16
- history . push ( '/about' ) ;
19
+ window . scrollTo ( { top : location . state . scrollY ?? 0 , behavior : 'auto' } ) ;
20
+ }
21
+ } , [ ] ) ;
22
+
23
+ const handleOverlayClick = ( ) => {
24
+ const scrollY = location . state ?. scrollY ;
25
+
26
+
27
+ // Restore after a short delay
28
+ setTimeout ( ( ) => {
29
+ if ( scrollY !== undefined ) {
30
+ window . scrollTo ( { top : scrollY , behavior : 'auto' } ) ;
31
+ }
32
+ } , 0 ) ;
33
+ history . replace ( '/about' ) ;
34
+ } ;
35
+
36
+ const handleClose = ( ) => {
37
+ const scrollY = location . state ?. scrollY ;
38
+
39
+ if ( location . state ?. fromAbout ) {
40
+ history . replace ( '/about' ) ;
41
+
42
+ setTimeout ( ( ) => {
43
+ if ( scrollY !== undefined ) {
44
+ window . scrollTo ( { top : scrollY , behavior : 'auto' } ) ;
45
+ }
46
+ } , 0 ) ;
17
47
} else {
18
48
history . goBack ( ) ;
19
49
}
@@ -24,13 +54,13 @@ export default function LargePortraitCardPage() {
24
54
< Route
25
55
path = "/about/:completeName"
26
56
render = { ( { history, match } ) => {
27
- const { completeName } = match . params ;
57
+ const { completeName } = match . params ; /* extract the dynamic part from the url i.e. the completeName*/
28
58
const teamMembers = getTeamByPersonName ( completeName ) ;
29
- const person = teamMembers . find ( person => person . completeName . replace ( / \s + / g, '' ) === completeName ) ;
59
+ const person = teamMembers . find ( ( person ) => person . completeName . replace ( / \s + / g , '' ) . normalize ( "NFD" ) . replace ( / [ \u0300 - \u036f ] / g, '' ) === completeName ) ;
30
60
if ( ! person ) return null ;
31
61
32
62
return (
33
- < div className = { styles . modal_overlay } onClick = { ( ) => history . push ( '/about' ) } >
63
+ < div className = { styles . modal_overlay } onClick = { handleOverlayClick } >
34
64
< div
35
65
className = { styles . modal_content }
36
66
onClick = { ( e ) => e . stopPropagation ( ) }
0 commit comments