|
| 1 | +var React = require('react/addons') |
| 2 | +var RouteHandler = require('react-router').RouteHandler |
| 3 | +var ReactRouter = require('react-router') |
| 4 | +var Link = ReactRouter.Link |
| 5 | + |
| 6 | +var userPlanets = [ |
| 7 | + { |
| 8 | + id: 1, |
| 9 | + name: 'testcat', |
| 10 | + profileName: 'TestCat' |
| 11 | + }, |
| 12 | + { |
| 13 | + id: 2, |
| 14 | + name: 'group1', |
| 15 | + profileName: 'Some Group#1' |
| 16 | + }, |
| 17 | + { |
| 18 | + id: 3, |
| 19 | + name: 'group2', |
| 20 | + profileName: 'Some Group#1' |
| 21 | + } |
| 22 | +] |
| 23 | + |
| 24 | +var PlanetNavigator = React.createClass({ |
| 25 | + propTypes: { |
| 26 | + currentPlanet: React.PropTypes.object |
| 27 | + }, |
| 28 | + render: function () { |
| 29 | + var planets = userPlanets.map(function (planet) { |
| 30 | + return ( |
| 31 | + <li key={planet.id} className={this.props.currentPlanet.name === planet.name ? 'active' : ''}><a>{planet.profileName[0]}</a></li> |
| 32 | + ) |
| 33 | + }.bind(this)) |
| 34 | + |
| 35 | + return ( |
| 36 | + <div className='PlanetNavigator'> |
| 37 | + <ul> |
| 38 | + {planets} |
| 39 | + </ul> |
| 40 | + </div> |
| 41 | + ) |
| 42 | + } |
| 43 | +}) |
| 44 | + |
| 45 | +var PlanetMain = React.createClass({ |
| 46 | + propTypes: { |
| 47 | + currentPlanet: React.PropTypes.object |
| 48 | + }, |
| 49 | + render: function () { |
| 50 | + return ( |
| 51 | + <div className='PlanetMain'> |
| 52 | + <SideNavigator currentPlanet={this.props.currentPlanet}/> |
| 53 | + <Screen currentPlanet={this.props.currentPlanet}/> |
| 54 | + </div> |
| 55 | + ) |
| 56 | + } |
| 57 | +}) |
| 58 | + |
| 59 | +var SideNavigator = React.createClass({ |
| 60 | + propTypes: { |
| 61 | + currentPlanet: React.PropTypes.shape({ |
| 62 | + name: React.PropTypes.string |
| 63 | + }) |
| 64 | + }, |
| 65 | + render: function () { |
| 66 | + var currentPlanetName = this.props.currentPlanet.name |
| 67 | + |
| 68 | + return ( |
| 69 | + <div className='SideNavigator'> |
| 70 | + <div className='nav-header'> |
| 71 | + <p className='planet-name'>{currentPlanetName}</p> |
| 72 | + <button className='menu-btn'> |
| 73 | + <i className='fa fa-chevron-down'></i> |
| 74 | + </button> |
| 75 | + </div> |
| 76 | + <button className='btn-primary btn-block'> |
| 77 | + <i className='fa fa-rocket fa-fw'/> Launch |
| 78 | + </button> |
| 79 | + <nav> |
| 80 | + <Link to='dashboard' params={{planetName: currentPlanetName}}> |
| 81 | + <i className='fa fa-home fa-fw'/> Home |
| 82 | + </Link> |
| 83 | + <Link to='snippets' params={{planetName: currentPlanetName}}> |
| 84 | + <i className='fa fa-code fa-fw'/> Snippets |
| 85 | + </Link> |
| 86 | + <Link to='blueprint' params={{planetName: currentPlanetName}}> |
| 87 | + <i className='fa fa-wrench fa-fw'/> Blueprints |
| 88 | + </Link> |
| 89 | + </nav> |
| 90 | + </div> |
| 91 | + ) |
| 92 | + } |
| 93 | +}) |
| 94 | + |
| 95 | +var Screen = React.createClass({ |
| 96 | + render: function () { |
| 97 | + return ( |
| 98 | + <div className='Screen'> |
| 99 | + <RouteHandler/> |
| 100 | + </div> |
| 101 | + ) |
| 102 | + } |
| 103 | +}) |
| 104 | + |
| 105 | +module.exports = React.createClass({ |
| 106 | + mixins: [ReactRouter.Navigation], |
| 107 | + propTypes: { |
| 108 | + params: React.PropTypes.object, |
| 109 | + planetName: React.PropTypes.string |
| 110 | + }, |
| 111 | + render: function () { |
| 112 | + var currentPlanetName = this.props.params.planetName |
| 113 | + var currentPlanet = null |
| 114 | + userPlanets.some(function (planet) { |
| 115 | + if (planet.name === currentPlanetName) { |
| 116 | + currentPlanet = planet |
| 117 | + return true |
| 118 | + } |
| 119 | + return false |
| 120 | + }) |
| 121 | + if (currentPlanet == null) { |
| 122 | + var redirectTo = userPlanets[0].name |
| 123 | + this.transitionTo('planet', {planetName: redirectTo}) |
| 124 | + return ( |
| 125 | + <div className='PlanetContainer'> |
| 126 | + Redirecting... |
| 127 | + </div> |
| 128 | + ) |
| 129 | + } |
| 130 | + |
| 131 | + return ( |
| 132 | + <div className='PlanetContainer'> |
| 133 | + <PlanetNavigator currentPlanet={currentPlanet}/> |
| 134 | + <PlanetMain currentPlanet={currentPlanet}/> |
| 135 | + </div> |
| 136 | + ) |
| 137 | + } |
| 138 | +}) |
0 commit comments