forked from amyjko/faculty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
125 lines (101 loc) · 3.88 KB
/
app.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
import React from 'react';
import ReactDOM from 'react-dom';
import { Route, BrowserRouter, Switch, withRouter } from 'react-router-dom';
import { Biography } from './components/bio';
import { ContactInfo } from './components/contact';
import { Publications } from './components/publications';
import { Posts } from './components/posts';
import { Impact } from './components/impact';
import { Students } from './components/students';
import { Header } from './components/header';
import { Projects } from './components/projects';
import { Reading } from './components/reading';
import { Advice } from './components/advice';
import { Teaching } from './components/teaching';
import { Talks } from './components/talks';
import { Books } from './components/books';
import { Vita } from './components/cv';
import { CER } from './components/cer';
import { Unknown } from './components/unknown';
import { Footer } from './components/footer';
import 'bootstrap';
var webRoot = "/ajko" + (window.location.pathname.includes("/test") ? "/test" : "");
// Polyfill startsWith
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position){
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}
class App extends React.Component {
constructor(props) {
super(props);
this.ref = React.createRef();
this.handleKeyPress = this.handleKeyPress.bind(this);
this.links = [
"/",
"/students",
"/publications",
"/posts",
"/talks",
"/teaching",
"/books",
"/impact",
"/advice",
"/bio",
"/contact"
];
}
getWebRoot() { return this.props.root; }
handleKeyPress(event) {
var oldIndex = this.links.indexOf(this.props.location.pathname);
var newIndex = oldIndex;
if(event.keyCode === 37) { newIndex = oldIndex === 0 ? index = this.links.length - 1 : oldIndex - 1; }
if(event.keyCode === 39) { newIndex = oldIndex === this.links.length - 1 ? oldIndex = 0 : oldIndex + 1; }
if(oldIndex !== newIndex)
this.props.history.push(this.links[newIndex]);
}
componentDidMount() {
this.focusApp();
}
componentDidUpdate() {
this.focusApp();
}
focusApp() {
if(this.ref.current)
this.ref.current.focus();
}
render() {
var currentRoute = this.props.location.pathname;
// Return the single page app.
return (
<div className="container" onKeyDown={this.handleKeyPress} tabIndex="0" ref={this.ref}>
{currentRoute === "/cv" ? null : <Header path={currentRoute} app={this} />}
<Switch>
<Route exact path="/" render={(props) => <Projects {...props} app={this} />} />
<Route path="/bio" render={(props) => <Biography {...props} app={this} />} />
<Route path="/publications/:paper?" render={(props) => <Publications {...props} app={this} />} />
<Route path="/posts" render={(props) => <Posts {...props} app={this} />} />
<Route path="/impact" component={Impact}/>
<Route path="/reading" component={Reading}/>
<Route path="/advice" render={(props) => <Advice {...props} app={this} />} />
<Route path="/teaching" render={(props) => <Teaching {...props} app={this} />} />
<Route path="/talks" render={(props) => <Talks {...props} app={this} />} />
<Route path="/books" render={(props) => <Books {...props} app={this} />} />
<Route path="/contact" render={(props) => <ContactInfo {...props} app={this} />} />
<Route path="/students/:student?" render={(props) => <Students {...props} app={this} />} />
<Route path="/cv" render={(props) => <Vita {...props} app={this} />} />
<Route path="/cer" component={CER}/>
<Route path="*" component={Unknown}/>
</Switch>
<Footer/>
</div>
)
}
}
var AppWithRouter = withRouter(App);
ReactDOM.render((
<BrowserRouter basename={webRoot}>
<Route path="/" render={(props) => <AppWithRouter {...props} root={webRoot}/> } />
</BrowserRouter>
), document.getElementById('app'));