-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.jsx
93 lines (78 loc) · 3.1 KB
/
index.jsx
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
import React from 'react';
import { render } from 'react-dom';
import { Router, Route, IndexRoute, useRouterHistory } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import { createHistory } from "history";
import 'current-input';
import { Provider } from 'react-redux';
import { actions, store } from './core/store';
import About from './components/About';
import App from './components/App';
import Bio from './components/Bio';
import Chasm from './components/Chasm';
import Home from './components/Home';
import PageNotFound from './components/PageNotFound';
import Prism from './components/Prism';
import Artifact from './components/Artifact';
import ArtifactTheme from './components/ArtifactTheme';
import Archive from './components/Archive';
import { SearchResultsPage } from './components/Search';
import config from './config';
const browserHistory = syncHistoryWithStore(useRouterHistory(createHistory)({
basename: config.basename
}), store);
const routes = (
<Route actions={actions} path="/" component={App}>
<IndexRoute component={Home} section="home" page="home" />
<Route path="about" component={About} title="About" section="about" page="about" />
<Route path="about/bios/:slug" component={Bio} section="about" page="bio" />
<Route path="chasm" component={Chasm} title="Chasm" section="chasm" page="chasm" />
<Route path="prism" component={Prism} title="Prism" section="prism" page="prism" />
<Route path="archive" component={Archive} section="archive" page="archive" />
<Route path="artifacts/theme/:slug" component={ArtifactTheme} section="archive" page="theme" />
<Route path="artifacts/:slug" component={Artifact} section="archive" page="artifact" />
<Route path="search/:query" component={SearchResultsPage} section="search" page="search-results" />
<Route path="*" component={PageNotFound} />
</Route>
);
function onRouteUpdate() {
window.scrollTo(0, 0);
const section = this.state.routes[this.state.routes.length - 1].section;
toggleSectionClass(section);
const page = this.state.routes[this.state.routes.length - 1].page;
togglePageClass(page);
}
function togglePageClass(page) {
const currentPage = `${page}-page`;
document.body.classList.add();
const classList = document.body.classList;
for (let i = 0; i < classList.length; i++) {
const className = classList[i];
if (className !== currentPage && className.endsWith('-page')) {
classList.remove(className);
}
}
document.body.classList.add(currentPage);
}
function toggleSectionClass(section) {
const currentSection = `${section}-section`;
document.body.classList.add();
const classList = document.body.classList;
for (let i = 0; i < classList.length; i++) {
const className = classList[i];
if (className !== currentSection && className.endsWith('-section')) {
classList.remove(className);
}
}
document.body.classList.add(currentSection);
}
render(
<Provider store={store}>
<Router
history={browserHistory}
onUpdate={onRouteUpdate}
routes={routes}
/>
</Provider>,
document.getElementById('root')
);