1
1
/*jshint esversion: 6 */
2
+ /* globals document */
2
3
import React from 'react' ;
3
4
import ReactDOM from 'react-dom' ;
4
5
@@ -27,16 +28,65 @@ import AuthStore from './passport/auth-store';
27
28
var auth = new AuthStore ( ) ;
28
29
29
30
const AuthRedirect = < Redirect to = { { pathname : '/' } } /> ;
31
+
30
32
const workspaceListStore = new WorkspaceListStore ( ) ;
31
33
34
+ const singWorkspaceStores = { } ;
35
+ const fixitStores = { } ;
36
+ const singleMapStores = { } ;
37
+
38
+ function getWorkspaceStore ( workspaceID ) {
39
+ Object . keys ( singWorkspaceStores ) . forEach ( function ( key , index ) {
40
+ if ( key === workspaceID ) {
41
+ singWorkspaceStores [ key ] . redispatch ( ) ;
42
+ return ;
43
+ }
44
+ singWorkspaceStores [ key ] . undispatch ( ) ;
45
+ } ) ;
46
+ if ( ! singWorkspaceStores [ workspaceID ] ) {
47
+ singWorkspaceStores [ workspaceID ] = new SingleWorkspaceStore ( workspaceID ) ;
48
+ }
49
+ return singWorkspaceStores [ workspaceID ] ;
50
+ }
51
+
52
+ function getFixitStore ( workspaceID ) {
53
+ Object . keys ( fixitStores ) . forEach ( function ( key , index ) {
54
+ if ( key === workspaceID ) {
55
+ fixitStores [ key ] . redispatch ( ) ;
56
+ return ;
57
+ }
58
+ fixitStores [ key ] . undispatch ( ) ;
59
+ } ) ;
60
+ if ( ! fixitStores [ workspaceID ] ) {
61
+ fixitStores [ workspaceID ] = new FixitStore ( workspaceID ) ;
62
+ }
63
+ return fixitStores [ workspaceID ] ;
64
+ }
65
+
66
+ function getSingleMapStore ( mapID ) {
67
+ Object . keys ( singleMapStores ) . forEach ( function ( key , index ) {
68
+ if ( key === mapID ) {
69
+ singleMapStores [ key ] . redispatch ( ) ;
70
+ return ;
71
+ }
72
+ singleMapStores [ key ] . undispatch ( ) ;
73
+ } ) ;
74
+ if ( ! singleMapStores [ mapID ] ) {
75
+ singleMapStores [ mapID ] = new SingleMapStore ( mapID ) ;
76
+ }
77
+ return singleMapStores [ mapID ] ;
78
+ }
79
+
32
80
ReactDOM . render (
33
81
< Router >
34
82
< Switch >
35
83
< Route exact path = "/"
36
84
component = {
37
85
( props ) =>
38
- ( auth . loggedIn ( props . history )
39
- ? < WorkspaceListPage auth = { auth } history = { props . history } workspaceListStore = { workspaceListStore } />
86
+ ( auth . loggedIn ( props . history ) ? < WorkspaceListPage
87
+ auth = { auth }
88
+ history = { props . history }
89
+ workspaceListStore = { workspaceListStore } />
40
90
: < SplashPage auth = { auth } history = { props . history } /> )
41
91
} />
42
92
< Route exact path = "/login"
@@ -45,22 +95,42 @@ ReactDOM.render(
45
95
( auth . loggedIn ( props . history ) ? AuthRedirect
46
96
: < LoginPage auth = { auth } history = { props . history } /> )
47
97
} />
48
- < Route exact path = "/workspace/:workspaceID"
49
- render = {
50
- ( props ) =>
51
- ( auth . loggedIn ( props . history )
52
- ? < MapListPage singleWorkspaceStore = { new SingleWorkspaceStore ( props . match . params . workspaceID ) } auth = { auth } history = { props . history } />
53
- : AuthRedirect )
54
- } />
55
- < Route exact path = "/map/:mapID"
56
- render = {
57
- ( props ) =>
58
- ( auth . loggedIn ( props . history )
59
- ? < MapEditorPage auth = { auth } history = { props . history } singleMapStore = { new SingleMapStore ( props . match . params . mapID ) } />
60
- : AuthRedirect ) } />
61
- < Route exact path = "/fixit/:workspaceID"
62
- render = { props =>
63
- ( auth . loggedIn ( props . history ) ? < FixitPage auth = { auth } history = { props . history } fixitStore = { new FixitStore ( props . match . params . workspaceID ) } /> : AuthRedirect ) } />
98
+ < Route path = "/(workspace|fixit)/:workspaceID" render = { ( props ) => {
99
+ if ( ! auth . loggedIn ( ) ) {
100
+ return AuthRedirect ;
101
+ }
102
+ const workspaceID = props . match . params . workspaceID ;
103
+ const singleWorkspaceStore = getWorkspaceStore ( workspaceID ) ;
104
+ const fixitStore = getFixitStore ( workspaceID ) ;
105
+
106
+ return (
107
+ < Switch >
108
+ < Route exact path = "/workspace/:workspaceID" >
109
+ < MapListPage
110
+ auth = { auth }
111
+ history = { props . history }
112
+ singleWorkspaceStore = { singleWorkspaceStore } />
113
+ </ Route >
114
+ < Route exact path = "/fixit/:workspaceID" >
115
+ < FixitPage
116
+ auth = { auth }
117
+ history = { props . history }
118
+ singleWorkspaceStore = { singleWorkspaceStore }
119
+ fixitStore = { fixitStore } />
120
+ </ Route >
121
+ </ Switch >
122
+ ) ;
123
+ }
124
+ } >
125
+ </ Route >
126
+ < Route exact path = "/map/:mapID"
127
+ render = {
128
+ ( props ) =>
129
+ ( auth . loggedIn ( ) ? < MapEditorPage
130
+ auth = { auth }
131
+ history = { props . history }
132
+ singleMapStore = { getSingleMapStore ( props . match . params . mapID ) } />
133
+ : AuthRedirect ) } />
64
134
< Redirect from = "*" to = "/" />
65
135
</ Switch >
66
136
</ Router > , document . getElementById ( 'app-container' ) ) ;
0 commit comments