-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
111 lines (105 loc) · 4.7 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter, Switch, Route, Redirect } from 'react-router-dom';
import { LocaleProvider } from 'antd';
import zh_CN from 'antd/lib/locale-provider/zh_CN';
import 'moment/locale/zh-cn';
import { Provider } from "mobx-react";
import { onSnapshot } from "mobx-state-tree"
import './index.css';
import registerServiceWorker from './registerServiceWorker';
import { Store } from "./stores";
import Index from "./pages/Index";
import WrappedSignin from "./pages/Signin";
import WrappedSignUp from "./pages/Signup";
import Home from "./pages/Home";
import CreateBook from 'pages/CreateBook';
import MyWorkspaces from 'pages/Home/Workspaces';
import CreateWorkspace from 'pages/Home/CreateWorkspace';
import Library from "./pages/Library";
import Book from 'pages/Book';
import Reader from "./pages/Reader";
import Editor from 'pages/Editor';
import KongfuSettings from "./pages/Home/KongfuSettings";
import Callback from "./pages/Signin/Callback";
import UserProfile from 'pages/Profile/UserProfile';
import UserSetting from "./pages/Home/UserSetting";
import BasicLayout from "./layouts/BasicLayout";
import InfoComplete from 'pages/Edu/InfoComplete';
import NarrowLayout from 'layouts/NarrowLayout';
import Courses from "./pages/Edu/Courses";
import Course from "./pages/Edu/Courses/Course";
import CreateCourse from "./pages/Edu/Courses/Create";
import CreateWork from 'pages/Edu/Courses/Course/CreateWork';
import Work from "./pages/Edu/Courses/Work";
import EditWork from 'pages/Edu/Courses/Course/EditWork';
if (window.location.hostname.substr(0, 3) == 'www') {
window.location.replace('http://kfcoding.com');
}
const store = Store.create(
{}
);
onSnapshot(store, (snapshot) => {
console.dir(snapshot)
})
const fakeAuth = {
isAuthenticated: () => {
return localStorage.getItem('token') ? true : false;
},
authenticate(cb) {
this.isAuthenticated = true
setTimeout(cb, 100)
},
signout(cb) {
this.isAuthenticated = false
setTimeout(cb, 100)
}
}
const PrivateRoute = ({component: Component, ...rest}) => (
<Route {...rest} render={(props) => (
fakeAuth.isAuthenticated() === true
? <Component {...props} />
: <Redirect to='/signin'/>
)}/>
)
ReactDOM.render(
<LocaleProvider locale={zh_CN}>
<Provider store={store}>
<BrowserRouter>
<Switch>
<Route path='/' exact component={Index}/>
<Route path='/signup' exact component={WrappedSignUp}/>
<Route path='/signin' exact component={WrappedSignin}/>
<Route exact path='/editor/:kongfu_id' component={props => <Editor {...props}/>}/>
<Route path='/reader/:kongfu_id' component={props => <Reader {...props}/>}/>
<Route path='/auth/callback' component={Callback}/>
<Route path='/home' exact component={props => <BasicLayout><Home {...props}/></BasicLayout>}/>
<Route path='/library' component={Library}/>
<Route path='/books/create' exact component={CreateBook}/>
<Route path='/books/:kongfu_id' exact component={props => <BasicLayout><Book {...props}/></BasicLayout>}/>
<Route path='/books/:kongfu_id/settings' component={props => <KongfuSettings {...props}/>}/>
<Route path='/users/setting' exact component={UserSetting}/>
<Route path='/users/:user_id' exact
component={props => <BasicLayout><UserProfile {...props}/></BasicLayout>}/>
<Route path='/home/workspaces/create' exact component={CreateWorkspace}/>
<Route path='/home/workspaces' exact
component={props => <BasicLayout><MyWorkspaces {...props}/></BasicLayout>}/>
<Route path='/complete' exact component={props => <NarrowLayout><InfoComplete {...props}/></NarrowLayout>}/>
<PrivateRoute path='/courses' exact component={props => <NarrowLayout><Courses {...props}/></NarrowLayout>}/>
<Route path='/courses/create' exact
component={props => <NarrowLayout><CreateCourse {...props}/></NarrowLayout>}/>
<Route path='/courses/:course_id' exact
component={props => <NarrowLayout><Course {...props}/></NarrowLayout>}/>
<Route path='/courses/:course_id/works/create' exact
component={props => <NarrowLayout><CreateWork {...props}/></NarrowLayout>}/>
<Route path='/works/:work_id/submissions' exact
component={props => <NarrowLayout><Work {...props}/></NarrowLayout>}/>
<Route path='/works/:work_id/edit' exact
component={props => <NarrowLayout><EditWork {...props}/></NarrowLayout>}/>
</Switch>
</BrowserRouter>
</Provider>
</LocaleProvider>,
document.getElementById('root')
);
registerServiceWorker();