-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSidebar.js
126 lines (110 loc) · 3.69 KB
/
Sidebar.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import React, { Component } from 'react';
import Scrollspy from 'react-scrollspy';
import Scroll from './Scroll';
import avatar from '../assets/images/avatar.png';
import config from '../../config';
export class Sidebar extends Component {
constructor(props) {
super(props);
this.state = {
tabs: [
{ content: 'About', href: 'about' },
{ content: 'Experience', href: 'experience' },
{ content: 'Education', href: 'education' },
{ content: 'Skills', href: 'skills' },
// { content: 'Interests', href: 'interests' },
// { content: 'Awards', href: 'awards' },
],
collapsed: true
};
this.toggleNavbar = this.toggleNavbar.bind(this);
this.trackClick = this.trackClick.bind(this);
// this.gtag = window.gtag;
}
trackClick(e) {
console.log('trackClick', window.gtag);
const gtag = window && window.gtag;
if (gtag) {
console.log('tracking available');
gtag('event', 'sidebar-nav', {target: e.currentTarget.innerText});
} else{
console.log('no tracking available');
}
// gtag('event', 'share');
// ReactGA.pageview('Sidebar-nav');
// trackCustomEvent({
// // string - required - The object that was interacted with (e.g.video)
// category: "Special Button",
// // string - required - Type of interaction (e.g. 'play')
// action: "Click",
// // string - optional - Useful for categorizing events (e.g. 'Spring Campaign')
// label: "Gatsby Plugin Example Campaign",
// // number - optional - Numeric value associated with the event. (e.g. A product ID)
// value: 43
// })
}
toggleNavbar() {
this.setState({
collapsed: !this.state.collapsed,
tabs: this.state.tabs
});
console.log('state: ', this.state);
}
render() {
const collapsed = this.state.collapsed;
const classOne = collapsed ? 'collapse navbar-collapse' : 'collapse navbar-collapse show';
const classTwo = collapsed ? 'navbar-toggler navbar-toggler-right collapsed' : 'navbar-toggler navbar-toggler-right';
const { tabs } = this.state;
return (
<nav
className="navbar navbar-expand-lg navbar-dark bg-primary fixed-top"
id="sideNav"
>
<a className="navbar-brand" href="#page-top">
<span className="d-block d-lg-none">
{config.firstName} {config.lastName}
</span>
<span className="d-none d-lg-block">
<img
className="img-fluid img-profile rounded-circle mx-auto mb-2"
src={avatar}
alt=""
/>
</span>
</a>
<button
className={`${classTwo}`}
type="button"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
onClick={this.toggleNavbar}
>
<span className="navbar-toggler-icon"></span>
</button>
<div className={`${classOne}`} id="navbarSupportedContent">
<Scrollspy
items={tabs.map(s => s.href)}
currentClassName="active"
offset={-300}
className="navbar-nav"
>
{tabs.map((tab, i) => {
const { href, content } = tab;
return (
<li className="nav-item" key={href} onClick={this.trackClick}>
<Scroll type="id" element={href}>
<a className="nav-link" href={`#${href}`}>
{content}
</a>
</Scroll>
</li>
);
})}
</Scrollspy>
</div>
</nav>
);
}
}
export default Sidebar;