11import React from 'react' ;
2+ import { Link } from 'react-router' ;
3+ import ExampleViewer from './ExampleViewer' ;
24
35import SimpleExample from './Simple/index' ;
46import ManualRenderingExample from './ManualRendering/index' ;
@@ -17,41 +19,49 @@ const examples = [
1719 name : 'Simple' ,
1820 component : SimpleExample ,
1921 url : 'Simple/index' ,
22+ slug : 'webgl_simple' ,
2023 } ,
2124 {
2225 name : 'Cloth' ,
2326 component : ClothExample ,
2427 url : 'AnimationCloth/index' ,
28+ slug : 'webgl_cloth' ,
2529 } ,
2630 {
2731 name : 'Camera' ,
2832 component : CameraExample ,
2933 url : 'WebGLCameraExample/index' ,
34+ slug : 'webgl_camera' ,
3035 } ,
3136 {
3237 name : 'Geometries' ,
3338 component : GeometriesExample ,
3439 url : 'Geometries/index' ,
40+ slug : 'webgl_geometries' ,
3541 } ,
3642 {
3743 name : 'Geometry Shapes' ,
3844 component : GeometryShapesExample ,
3945 url : 'GeometryShapes/index' ,
46+ slug : 'webgl_geometry_shapes' ,
4047 } ,
4148 {
4249 name : 'Draggable Cubes' ,
4350 component : DraggableCubes ,
4451 url : 'DraggableCubes/index' ,
52+ slug : 'webgl_draggable_cubes' ,
4553 } ,
4654 {
4755 name : 'Physics' ,
4856 component : Physics ,
4957 url : 'Physics/index' ,
58+ slug : 'webgl_physics' ,
5059 } ,
5160 {
5261 name : 'Physics - MousePick' ,
5362 component : PhysicsMousePick ,
5463 url : 'Physics/mousePick' ,
64+ slug : 'webgl_physics_mousepick' ,
5565 } ,
5666 {
5767 separator : true ,
@@ -66,6 +76,7 @@ const examples = [
6676 name : 'Manual rendering' ,
6777 component : ManualRenderingExample ,
6878 url : 'ManualRendering/index' ,
79+ slug : 'advanced_manual_rendering' ,
6980 } ,
7081 {
7182 separator : true ,
@@ -75,74 +86,20 @@ const examples = [
7586 name : 'RotatingCubes - Through React' ,
7687 component : BenchmarkRotatingCubes ,
7788 url : 'Benchmark/RotatingCubes' ,
89+ slug : 'benchmarks_rotating_cubes_react' ,
7890 } ,
7991 {
8092 name : 'RotatingCubes - Direct Updates' ,
8193 component : RotatingCubesDirectUpdates ,
8294 url : 'Benchmark/RotatingCubesDirectUpdates' ,
95+ slug : 'benchmarks_rotating_cubes_direct' ,
8396 } ,
8497] ;
8598
86- class ExampleBrowser extends React . Component {
87- constructor ( props , context ) {
88- super ( props , context ) ;
89-
90- this . state = {
91- activeExample : null ,
92- viewerWidth : 0 ,
93- viewerHeight : 0 ,
94- } ;
95- }
96-
97- componentDidMount ( ) {
98- window . addEventListener ( 'resize' , this . _onWindowResize , false ) ;
99- }
100-
101- componentWillUnmount ( ) {
102- window . removeEventListener ( 'resize' , this . _onWindowResize , false ) ;
103- }
104-
105- _onWindowResize = ( ) => {
106- const viewer = this . refs . viewer ;
107-
108- this . setState ( {
109- viewerWidth : viewer . offsetWidth ,
110- viewerHeight : viewer . offsetHeight ,
111- } ) ;
112- } ;
113-
114- render ( ) {
115- let exampleContent = null ;
116-
117- const {
118- viewerWidth,
119- viewerHeight,
120- } = this . state ;
121-
122- let sourceButton = null ;
123-
124- if ( this . state . activeExample !== null ) {
125- const {
126- component : ExampleComponent ,
127- url,
128- } = examples [ this . state . activeExample ] ;
129-
130- exampleContent = ( < ExampleComponent
131- width = { viewerWidth }
132- height = { viewerHeight }
133- /> ) ;
134-
135- sourceButton = ( < div key = "src" id = "button" >
136- < a
137- href = { `https://github.com/toxicFork/react-three-renderer-example/blob/master/src/examples/${ url } .js` }
138- target = "_blank"
139- >
140- View source
141- </ a >
142- </ div > ) ;
143- }
144-
145- return ( < div >
99+ const ExampleBrowser = ( { params } ) => {
100+ const activeExample = params . slug && examples . find ( example => example . slug === params . slug ) ;
101+ return (
102+ < div >
146103 < div id = "panel" className = "collapsed" >
147104 < h1 > < a href = "https://github.com/toxicFork/react-three-renderer/" > react-three-renderer</ a > / examples</ h1 >
148105 < div id = "content" >
@@ -159,33 +116,25 @@ class ExampleBrowser extends React.Component {
159116 </ div > ) ;
160117 }
161118
162- const onLinkClick = ( ) => {
163- const viewer = this . refs . viewer ;
164-
165- this . setState ( {
166- viewerWidth : viewer . offsetWidth ,
167- viewerHeight : viewer . offsetHeight ,
168- activeExample : index ,
169- } ) ;
170- } ;
171-
172- return ( < div
173- className = "link"
119+ return ( < Link
120+ to = { `/${ example . slug } ` }
174121 key = { index }
175- onClick = { onLinkClick }
122+ className = "link"
123+ activeClassName = "selected"
176124 >
177125 { example . name }
178- </ div > ) ;
126+ </ Link > ) ;
179127 } ) }
180128 </ div >
181129 </ div >
182130 </ div >
183- < div id = "viewer" ref = "viewer" >
184- { exampleContent }
185- { sourceButton }
186- </ div >
187- </ div > ) ;
188- }
189- }
131+ < ExampleViewer example = { activeExample } />
132+ </ div >
133+ ) ;
134+ } ;
135+
136+ ExampleBrowser . propTypes = {
137+ params : React . PropTypes . object . isRequired ,
138+ } ;
190139
191140export default ExampleBrowser ;
0 commit comments