Skip to content

Commit 0b65a23

Browse files
Fix issues related to last names like for those having special characters.
Add logics to not scroll systematically to the top of the page when changing from about page to portrait ones and reciprocally.
1 parent 3756b2d commit 0b65a23

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed

src/components/about/LargePortraitCardPage.tsx

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,49 @@
11
import React from 'react';
22
import Layout from '@theme/Layout';
3-
import { useHistory, useLocation} from '@docusaurus/router';
3+
import { useHistory, useLocation } from '@docusaurus/router';
4+
import { useEffect } from 'react';
45
import { Route } from 'react-router-dom';
56
import { About } from '@site/src/components/about'
67
import LargePortraitCard from '@site/src/components/about/LargePortraitCard';
78
import { getTeamByPersonName } from '@site/src/components/about';
89
import styles from "@site/src/components/about/styles.module.css";
910

11+
12+
1013
export default function LargePortraitCardPage() {
1114
const location = useLocation();
1215
const history = useHistory();
1316

14-
function handleClose() {
17+
useEffect(() => {
1518
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);
1747
} else {
1848
history.goBack();
1949
}
@@ -24,13 +54,13 @@ export default function LargePortraitCardPage() {
2454
<Route
2555
path="/about/:completeName"
2656
render={({ history, match }) => {
27-
const { completeName } = match.params;
57+
const { completeName } = match.params; /* extract the dynamic part from the url i.e. the completeName*/
2858
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);
3060
if (!person) return null;
3161

3262
return (
33-
<div className={styles.modal_overlay} onClick={() => history.push('/about')}>
63+
<div className={styles.modal_overlay} onClick={handleOverlayClick}>
3464
<div
3565
className={styles.modal_content}
3666
onClick={(e) => e.stopPropagation()}

src/components/about/SmallPortraitCard.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import styles from "./styles.module.css";
22
import { useHistory } from "@docusaurus/router";
33
import Avatar from "./Avatar";
44

5-
export function SmallPortraitCard({ person}) {
5+
export function SmallPortraitCard({ person }) {
66
const history = useHistory();
77

88
function openDialog() {
9+
let completeName = person.completeName.replace(/\s+/g, '');
10+
const completeNameWithoutAccents = completeName
11+
.normalize("NFD")
12+
.replace(/[\u0300-\u036f]/g, '');
913
history.push({
10-
pathname: `/about/${person.completeName.replace(/\s+/g, '')}`,
11-
state: { fromAbout: true },
14+
pathname: `/about/${completeNameWithoutAccents}`,
15+
state: { fromAbout: true, scrollY: window.scrollY, },
1216
});
1317
}
1418

src/components/about/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import LinkToContact from "../home/LinkToContact";
66

77
export function getTeamByPersonName(name: string) {
88
for (const [teamName, members] of Object.entries(teams)) {
9-
const person = members.find((person) => person.completeName.replace(/\s+/g, '') === name);
9+
const person = members.find((person) => person.completeName.replace(/\s+/g, '').replace(/\s+/g, '').normalize("NFD").replace(/[\u0300-\u036f]/g, '') === name);
1010
if (person) {
1111
return members;
1212
}
File renamed without changes.

src/pages/about/Meriem.Benismail.tsx renamed to src/pages/about/MeriemBenIsmail.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import React from 'react';
2-
import Layout from '@theme/Layout';
3-
import { useHistory, useLocation} from '@docusaurus/router';
42
import LargePortraitCardPage from "@site/src/components/about/LargePortraitCardPage";
53

64
export default function AboutPage() {

0 commit comments

Comments
 (0)