-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathlayout.jsx
More file actions
91 lines (82 loc) · 2.71 KB
/
layout.jsx
File metadata and controls
91 lines (82 loc) · 2.71 KB
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
/**
* Layout component that queries for data
* with Gatsby's useStaticQuery component
*
* See: https://www.gatsbyjs.org/docs/use-static-query/
*/
import React, {useRef} from 'react';
import './layout.scss';
const getCookie = (name) => {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) {
return parts
.pop()
.split(';')
.shift();
}
return undefined;
};
const setReferrerCookie = () => {
const referrerUrl = document.referrer !== '' ? document.referrer : 'null';
const now = new Date();
const timeStamp = now.setDate(now.getDate() + 30);
const expiration = new Date(timeStamp).toUTCString();
const currentCookie = getCookie('referrer_url');
if (!referrerUrl.split('?')[0].includes('testsigma.com')) {
if (
referrerUrl !== ''
|| currentCookie === 'null'
|| currentCookie === undefined
) {
document.cookie = 'referrer_url=; expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/;secure';
document.cookie = `referrer_url=${referrerUrl};expires=${expiration};path=/;secure;`;
}
}
};
class Layout extends React.Component {
observer = null;
constructor(props) {
super(props);
this.state = { ...props };
}
componentDidMount() {
setReferrerCookie();
this.observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
const navElement = document.querySelector(
`.contextual-links a.dynamic-link__internal[href*="#${entry.target.id}"]`,
)
if (entry.isIntersecting) {
if (navElement && !navElement.classList.contains('border-red-100')) {
document.querySelectorAll('.contextual-links__link a.border-red-100.border-b-2').forEach(previousActive => {
previousActive.classList.remove('border-b-2', 'border-red-100');
})
navElement.classList.add('border-b-2', 'border-red-100');
}
}
})
}, {
threshold: 0.5,
});
const contextualLinks = document.querySelectorAll('h2');
contextualLinks.forEach(headerWithId => {
this.observer.observe(headerWithId);
});
}
componentWillUnmount() {
this.observer.disconnect()
this.observer = null
}
render() {
const { children } = this.state;
return (
<>
<main>
{children}
</main>
</>
);
}
}
export default Layout;