-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
92 lines (81 loc) · 2.59 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React, { useState, useEffect, useRef } from "react"
import { useTranslation } from 'gatsby-plugin-react-i18next';
import { graphql } from 'gatsby';
import Layout from "../components/layout"
import Seo from "../components/seo"
import Hero from "../components/hero";
import Service from "../components/service";
import Team from "../components/team";
import Steps from "../components/steps";
import Join from "../components/join";
import Contact from "../components/contact";
import AOS from 'aos';
import 'aos/dist/aos.css';
export default function IndexPage({ pageContext }) {
const locale = pageContext.language
// Set who in the team is being featured
const pausedRef = useRef(false);
const [teamIndex, setTeamIndex ] = useState(0);
// You can access the elements with itemsRef.current[n]
const sectionRefs = useRef([]);
// Compile all the refs
const addToRefs = (el) => {
if (el && !sectionRefs.current.includes(el)) {
sectionRefs.current.push(el)
}
}
useEffect(() => {
// initialize Animation on Scroll
AOS.init({ offset: 50 });
// Set up observer
const observer = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting && !pausedRef.current) {
const refIndex = parseInt(entry.target.dataset.step)
const top = sectionRefs.current[refIndex].offsetTop
window.scrollTo({ top, behavior: 'smooth' })
}
}, { threshold: 0.01 })
const refs = sectionRefs.current
// Observer to observe each ref
refs.forEach(ref => {
if (ref) {
observer.observe(ref)
}
})
// Clean up Observer to unobserve each ref
return () => {
refs.forEach(ref => {
if (ref) {
observer.unobserve(ref)
}
})
}
}, [sectionRefs, pausedRef])
const {t} = useTranslation();
return (
<Layout>
<Seo title={t('Home')} />
<div ref={addToRefs} data-step="0">
<Hero sectionRefs={sectionRefs} setTeamIndex={setTeamIndex} pausedRef={pausedRef} />
</div>
<div ref={addToRefs} data-step="1"><Service /></div>
<div ref={addToRefs} data-step="2"><Team teamIndex={teamIndex} setTeamIndex={setTeamIndex} locale={locale}/></div>
<div ref={addToRefs} data-step="3"><Steps /></div>
<div ref={addToRefs} data-step="4"><Join /></div>
<div ref={addToRefs} data-step="5"><Contact /></div>
</Layout>
);
};
export const query = graphql`
query($language: String!) {
locales: allLocale(filter: { language: {eq: $language} }) {
edges {
node {
ns
data
language
}
}
}
}
`;