From e0d52d357866de63843b8f252b69a744878c9d5b Mon Sep 17 00:00:00 2001 From: Rokt33r Date: Sat, 11 Jul 2015 10:53:04 +0900 Subject: [PATCH] refactor Router & add User settings --- browser/main/Components/LaunchModal.jsx | 2 +- browser/main/Containers/PlanetContainer.jsx | 60 ++++----- browser/main/Containers/UserContainer.jsx | 85 +++++++++++++ .../main/Containers/UserSettingContainer.jsx | 115 ++++++++++++++++++ browser/main/index.jsx | 19 +-- .../main/containers/UserSettingContainer.styl | 33 +++++ browser/styles/main/index.styl | 9 +- browser/styles/shared/modal.styl | 12 ++ browser/styles/vars.styl | 2 - 9 files changed, 290 insertions(+), 47 deletions(-) create mode 100644 browser/main/Containers/UserContainer.jsx create mode 100644 browser/main/Containers/UserSettingContainer.jsx create mode 100644 browser/styles/main/containers/UserSettingContainer.styl diff --git a/browser/main/Components/LaunchModal.jsx b/browser/main/Components/LaunchModal.jsx index ea3f72f5..a17baa17 100644 --- a/browser/main/Components/LaunchModal.jsx +++ b/browser/main/Components/LaunchModal.jsx @@ -130,7 +130,7 @@ var LaunchModal = React.createClass({
- +
{form}
diff --git a/browser/main/Containers/PlanetContainer.jsx b/browser/main/Containers/PlanetContainer.jsx index 235b01fd..3b750739 100644 --- a/browser/main/Containers/PlanetContainer.jsx +++ b/browser/main/Containers/PlanetContainer.jsx @@ -29,49 +29,44 @@ var userPlanets = [ } ] -var PlanetNavigator = React.createClass({ - propTypes: { - currentPlanet: React.PropTypes.object, - currentUser: React.PropTypes.object - }, - render: function () { - var planets = userPlanets.map(function (planet, index) { - return ( -
  • - {planet.profileName[0]} -
    ⌘{index + 1}
    -
  • - ) - }.bind(this)) - - return ( -
    - - - -
      - {planets} -
    - -
    - ) - } -}) - var PlanetHeader = React.createClass({ propTypes: { currentPlanet: React.PropTypes.object, currentUser: React.PropTypes.object }, + getInitialState: function () { + return { + isMenuDropDownOpen: false + } + }, + toggleMenuDropDown: function () { + this.setState({isMenuDropDownOpen: !this.state.isMenuDropDownOpen}, function () { + if (this.state.isMenuDropDownOpen) { + document.body.onclick = function () { + this.setState({isMenuDropDownOpen: false}, function () { + document.body.onclick = null + }) + }.bind(this) + } + }) + }, + interceptClick: function (e) { + e.stopPropagation() + }, render: function () { var currentPlanetName = this.props.currentPlanet.name return ( -
    +
    {currentPlanetName} - + @@ -143,7 +138,7 @@ var SideNavigator = React.createClass({ Snippets - Blueprints + Blueprints
    @@ -189,7 +184,6 @@ module.exports = React.createClass({ return (
    -
    ) diff --git a/browser/main/Containers/UserContainer.jsx b/browser/main/Containers/UserContainer.jsx new file mode 100644 index 00000000..828bf2ff --- /dev/null +++ b/browser/main/Containers/UserContainer.jsx @@ -0,0 +1,85 @@ +var React = require('react/addons') +var ReactRouter = require('react-router') +var Link = ReactRouter.Link +var RouteHandler = ReactRouter.RouteHandler + +// Dummy +var currentUser = { + name: 'testcat', + email: 'testcat@example.com', + profileName: 'Test Cat' +} + +var userPlanets = [ + { + id: 1, + name: 'testcat', + profileName: 'TestCat' + }, + { + id: 2, + name: 'group1', + profileName: 'Some Group#1' + }, + { + id: 3, + name: 'group2', + profileName: 'Some Group#1' + } +] + +var UserNavigator = React.createClass({ + propTypes: { + currentPlanet: React.PropTypes.object, + currentUser: React.PropTypes.object + }, + render: function () { + var planets = userPlanets.map(function (planet, index) { + return ( +
  • + {planet.profileName[0]} +
    ⌘{index + 1}
    +
  • + ) + }.bind(this)) + if (this.props.currentUser == null) { + return ( +
    +
    + ) + } + + return ( +
    + + + +
      + {planets} +
    + +
    + ) + } +}) + +module.exports = React.createClass({ + mixins: [React.addons.LinkedStateMixin, ReactRouter.Navigation], + render: function () { + var currentPlanetName = this.props.params.planetName + var currentPlanet = null + userPlanets.some(function (planet) { + if (planet.name === currentPlanetName) { + currentPlanet = planet + return true + } + return false + }) + return ( +
    + + +
    + ) + } +}) diff --git a/browser/main/Containers/UserSettingContainer.jsx b/browser/main/Containers/UserSettingContainer.jsx new file mode 100644 index 00000000..9fd08459 --- /dev/null +++ b/browser/main/Containers/UserSettingContainer.jsx @@ -0,0 +1,115 @@ +var React = require('react/addons') +var ReactRouter = require('react-router') +var Link = ReactRouter.Link + +var currentUser = { + name: 'testcat', + email: 'testcat@example.com', + profileName: 'Test Cat' +} + +var UserSettingNavigation = React.createClass({ + propTypes: { + currentUser: React.PropTypes.shape({ + name: React.PropTypes.string + }) + }, + changeFactory: function (current) { + return function () { + this.props.changeCurrent(current) + }.bind(this) + }, + render: function () { + return ( +
    +
    {this.props.currentUser.name}
    + +
    + ) + } +}) + +var UserSettingMain = React.createClass({ + propTypes: { + currentUser: React.PropTypes.shape({ + name: React.PropTypes.string + }) + }, + render: function () { + var view + + switch (this.props.current) { + case 'profile': + view = ( +
    +

    User Info

    +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    +

    Password Reset

    +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    + ) + break + default: + view = ( +
    + Missing... +
    + ) + break + } + return ( +
    + {view} +
    + ) + } +}) + +module.exports = React.createClass({ + mixins: [React.addons.LinkedStateMixin, ReactRouter.Navigation], + getInitialState: function () { + return { + current: 'profile' + } + }, + changeCurrent: function (current) { + this.setState({ + current: current + }) + }, + render: function () { + return ( +
    + + +
    + ) + } +}) diff --git a/browser/main/index.jsx b/browser/main/index.jsx index 47b75762..9425e191 100644 --- a/browser/main/index.jsx +++ b/browser/main/index.jsx @@ -12,21 +12,26 @@ var MainContainer = require('./Containers/MainContainer.jsx') var LoginContainer = require('./Containers/LoginContainer.jsx') var RegisterContainer = require('./Containers/RegisterContainer.jsx') +var UserContainer = require('./Containers/UserContainer.jsx') +var UserSettingContainer = require('./Containers/UserSettingContainer.jsx') var PlanetContainer = require('./Containers/PlanetContainer.jsx') - -var Dashboard = require('./Containers/DashboardContainer.jsx') +var DashboardContainer = require('./Containers/DashboardContainer.jsx') var SnippetContainer = require('./Containers/SnippetContainer.jsx') var BlueprintContainer = require('./Containers/BlueprintContainer.jsx') var routes = ( - - - - - + + + + + + + + + ) diff --git a/browser/styles/main/containers/UserSettingContainer.styl b/browser/styles/main/containers/UserSettingContainer.styl new file mode 100644 index 00000000..31014ed9 --- /dev/null +++ b/browser/styles/main/containers/UserSettingContainer.styl @@ -0,0 +1,33 @@ +.UserSettingContainer + absolute top bottom right + left 50px + .UserSettingNavigation + absolute top bottom left + width 200px + padding 15px + box-sizing border-box + border-right solid 1px borderColor + .userName + font-size 2.0em + margin 10px 0 + color brandColor + a + display block + color textColor + width 100% + padding 15px + margin-bottom 5px + border-radius 10px + box-sizing border-box + cursor pointer + &:hover, &.hover + color brandColor + background-color hoverBackgroundColor + &:active, &.active + color brandColor + + .UserSettingMain + absolute top bottom right + left 200px + padding 10px + box-sizing border-box diff --git a/browser/styles/main/index.styl b/browser/styles/main/index.styl index 00c18581..49e21dca 100644 --- a/browser/styles/main/index.styl +++ b/browser/styles/main/index.styl @@ -82,7 +82,7 @@ textarea.block-input h1, h2 margin 5px auto 25px -.PlanetNavigator +.UserNavigator background-color planetNavBgColor absolute left top bottom width 50px @@ -100,7 +100,6 @@ textarea.block-input &.active, &:active, &.focus, &:focus, &.hover, &:hover img opacity 1 - ul>li padding 10px 3px .shortCut @@ -117,6 +116,7 @@ textarea.block-input height 44px text-align center background-color planetAnchorBgColor + text-decoration none color planetAnchorColor line-height 44px font-size 1.1em @@ -153,11 +153,12 @@ textarea.block-input color white .PlanetContainer - fullsize() -.PlanetMain absolute top bottom right left 50px +.PlanetMain + fullsize() + .PlanetHeader absolute left right top overflow-y hidden diff --git a/browser/styles/shared/modal.styl b/browser/styles/shared/modal.styl index 4b635287..7b700d90 100644 --- a/browser/styles/shared/modal.styl +++ b/browser/styles/shared/modal.styl @@ -25,6 +25,18 @@ float right .launch-modal + .modal-tab + .btn-primary, .btn-default + margin 0 + border-radius 0 + &:nth-child(1) + border-top-left-radius 10px + border-bottom-left-radius 10px + &:nth-child(2) + border-left 0 + border-top-right-radius 10px + border-bottom-right-radius 10px + .ace_editor height 300px border-radius 5px diff --git a/browser/styles/vars.styl b/browser/styles/vars.styl index d9e3f2a4..b17d438c 100644 --- a/browser/styles/vars.styl +++ b/browser/styles/vars.styl @@ -7,8 +7,6 @@ buttonBorderColor = #4C4C4C lightButtonColor = #898989 - - hoverBackgroundColor= transparentify(#444, 3%)