Skip to content

Commit d8cb93f

Browse files
committed
on Refactor... BoostIO#2
1 parent 23b8b49 commit d8cb93f

16 files changed

Lines changed: 393 additions & 248 deletions

browser/main/Components/CodeEditor.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module.exports = React.createClass({
2020
var session = editor.getSession()
2121
if (this.props.mode != null && this.props.mode.length > 0) {
2222
session.setMode('ace/mode/' + this.props.mode)
23+
} else {
24+
session.setMode('ace/mode/text')
2325
}
2426
session.setUseSoftTabs(true)
2527
session.setOption('useWorker', false)
@@ -40,7 +42,12 @@ module.exports = React.createClass({
4042
this.state.editor.clearSelection()
4143
}
4244
if (prevProps.mode !== this.props.mode) {
43-
this.state.editor.getSession().setMode('ace/mode/' + this.props.mode)
45+
var session = this.state.editor.getSession()
46+
if (this.props.mode != null && this.props.mode.length > 0) {
47+
session.setMode('ace/mode/' + this.props.mode)
48+
} else {
49+
session.setMode('ace/mode/text')
50+
}
4451
}
4552
},
4653
render: function () {

browser/main/Components/CodeViewer.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ module.exports = React.createClass({
2121
var session = editor.getSession()
2222
if (this.props.mode != null && this.props.mode.length > 0) {
2323
session.setMode('ace/mode/' + this.props.mode)
24+
} else {
25+
session.setMode('ace/mode/text')
2426
}
2527
session.setUseSoftTabs(true)
2628
session.setOption('useWorker', false)
@@ -34,7 +36,12 @@ module.exports = React.createClass({
3436
this.state.editor.clearSelection()
3537
}
3638
if (prevProps.mode !== this.props.mode) {
37-
this.state.editor.getSession().setMode('ace/mode/' + this.props.mode)
39+
var session = this.state.editor.getSession()
40+
if (this.props.mode != null && this.props.mode.length > 0) {
41+
session.setMode('ace/mode/' + this.props.mode)
42+
} else {
43+
session.setMode('ace/mode/text')
44+
}
3845
}
3946
},
4047
render: function () {

browser/main/Components/HomeNavigator.jsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var UserStore = require('../Stores/UserStore')
1313

1414
var PreferencesModal = require('./PreferencesModal')
1515
var PlanetCreateModal = require('./PlanetCreateModal')
16+
var TeamCreateModal = require('./TeamCreateModal')
1617
var ProfileImage = require('./ProfileImage')
1718

1819
module.exports = React.createClass({
@@ -32,8 +33,11 @@ module.exports = React.createClass({
3233
break
3334
}
3435
},
36+
openTeamCreateModal: function () {
37+
this.openModal(TeamCreateModal, {user: this.state.currentUser, transitionTo: this.transitionTo})
38+
},
3539
openPreferencesModal: function () {
36-
this.openModal(PreferencesModal)
40+
this.openModal(PreferencesModal, {currentUser: this.state.currentUser})
3741
},
3842
openPlanetCreateModal: function () {
3943
this.openModal(PlanetCreateModal, {transitionTo: this.transitionTo})
@@ -75,7 +79,9 @@ module.exports = React.createClass({
7579
)
7680
}
7781

78-
var planets = ((this.state.currentUser == null || this.state.currentUser.Planets == null) ? [] : this.state.currentUser.Planets).map(function (planet, index) {
82+
var planets = (this.state.currentUser.Planets.concat(this.state.currentUser.Teams.reduce(function (planets, team) {
83+
return planets.concat(team.Planets)
84+
}, []))).map(function (planet, index) {
7985
return (
8086
<li key={planet.id} className={params.userName === planet.userName && params.planetName === planet.name ? 'active' : ''}>
8187
<Link to='planet' params={{userName: planet.userName, planetName: planet.name}}>
@@ -103,6 +109,15 @@ module.exports = React.createClass({
103109
)
104110
},
105111
renderPopup: function () {
112+
var teams = this.state.currentUser.Teams == null ? [] : this.state.currentUser.Teams.map(function (team) {
113+
return (
114+
<li key={'user-' + team.id}>
115+
<Link to='userHome' params={{userName: team.name}} className='userName'>{team.profileName} ({team.name})</Link>
116+
<div className='userSetting'><i className='fa fa-gear'/></div>
117+
</li>
118+
)
119+
})
120+
106121
return (
107122
<div ref='profilePopup' className={'profilePopup' + (this.state.isProfilePopupOpen ? '' : ' close')}>
108123
<div className='profileGroup'>
@@ -111,7 +126,7 @@ module.exports = React.createClass({
111126
</div>
112127
<ul className='profileGroupList'>
113128
<li>
114-
<Link to='userHome' params={{userName: this.state.currentUser.name}} className='userName'>Profile</Link>
129+
<Link to='userHome' params={{userName: this.state.currentUser.name}} className='userName'>Profile ({this.state.currentUser.name})</Link>
115130
<div className='userSetting'><i className='fa fa-gear'/></div>
116131
</li>
117132
</ul>
@@ -122,20 +137,9 @@ module.exports = React.createClass({
122137
<span>Team</span>
123138
</div>
124139
<ul className='profileGroupList'>
140+
{teams}
125141
<li>
126-
<div className='userName'>A team</div>
127-
<div className='userSetting'><i className='fa fa-gear'/></div>
128-
</li>
129-
<li>
130-
<div className='userName'>B team</div>
131-
<div className='userSetting'><i className='fa fa-gear'/></div>
132-
</li>
133-
<li>
134-
<div className='userName'>C team</div>
135-
<div className='userSetting'><i className='fa fa-gear'/></div>
136-
</li>
137-
<li>
138-
<button className='createNewTeam'><i className='fa fa-plus-square-o'/> create new team</button>
142+
<button onClick={this.openTeamCreateModal} className='createNewTeam'><i className='fa fa-plus-square-o'/> create new team</button>
139143
</li>
140144
</ul>
141145
</div>

browser/main/Components/NoteForm.jsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,17 @@ var getOptions = function (input, callback) {
2929
})
3030
}
3131

32-
var NoteForm = React.createClass({
32+
var EDIT_MODE = 0
33+
var PREVIEW_MODE = 1
34+
35+
module.exports = React.createClass({
3336
mixins: [LinkedState, ReactRouter.State, Markdown],
3437
propTypes: {
3538
planet: React.PropTypes.object,
3639
close: React.PropTypes.func,
3740
transitionTo: React.PropTypes.func,
3841
note: React.PropTypes.object
3942
},
40-
statics: {
41-
EDIT_MODE: 0,
42-
PREVIEW_MODE: 1
43-
},
4443
getInitialState: function () {
4544
var note = Object.assign({
4645
title: '',
@@ -55,7 +54,7 @@ var NoteForm = React.createClass({
5554
})
5655
return {
5756
note: note,
58-
mode: NoteForm.EDIT_MODE
57+
mode: EDIT_MODE
5958
}
6059
},
6160
componentDidMount: function () {
@@ -72,7 +71,7 @@ var NoteForm = React.createClass({
7271
this.setState({note: note})
7372
},
7473
togglePreview: function () {
75-
this.setState({mode: this.state.mode === NoteForm.EDIT_MODE ? NoteForm.PREVIEW_MODE : NoteForm.EDIT_MODE})
74+
this.setState({mode: this.state.mode === EDIT_MODE ? PREVIEW_MODE : EDIT_MODE})
7675
},
7776
submit: function () {
7877
var planet = this.props.planet
@@ -102,7 +101,7 @@ var NoteForm = React.createClass({
102101
}
103102
},
104103
render: function () {
105-
var content = this.state.mode === NoteForm.EDIT_MODE ? (
104+
var content = this.state.mode === EDIT_MODE ? (
106105
<div className='form-group'>
107106
<CodeEditor onChange={this.handleContentChange} code={this.state.note.content} mode={'markdown'}/>
108107
</div>
@@ -134,7 +133,7 @@ var NoteForm = React.createClass({
134133
</div>
135134

136135
<div className='modal-footer'>
137-
<button onClick={this.togglePreview} className={'btn-default' + (this.state.mode === NoteForm.PREVIEW_MODE ? ' active' : '')}>Preview mode</button>
136+
<button onClick={this.togglePreview} className={'btn-default' + (this.state.mode === PREVIEW_MODE ? ' active' : '')}>Preview mode</button>
138137
<div className='modal-control'>
139138
<button onClick={this.props.close} className='btn-default'>Cancel</button>
140139
<button onClick={this.submit} className='btn-primary'>Launch</button>
@@ -144,5 +143,3 @@ var NoteForm = React.createClass({
144143
)
145144
}
146145
})
147-
148-
module.exports = NoteForm

browser/main/Components/PlanetCreateModal.jsx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ module.exports = React.createClass({
2222
user: currentUser,
2323
planet: {
2424
name: '',
25-
OwnerId: currentUser.id,
2625
public: true
27-
}
26+
},
27+
ownerName: currentUser.name
2828
}
2929
},
3030
componentDidMount: function () {
@@ -36,23 +36,12 @@ module.exports = React.createClass({
3636
}
3737
},
3838
handleSubmit: function () {
39-
Hq.createPlanet(this.state.user.name, this.state.planet)
39+
Hq.createPlanet(this.state.ownerName, this.state.planet)
4040
.then(function (res) {
4141
var planet = res.body
4242

43-
var currentUser = JSON.parse(localStorage.getItem('currentUser'))
43+
PlanetStore.Actions.update(planet)
4444

45-
var isNew = !currentUser.Planets.some(function (_planet, index) {
46-
if (planet.id === _planet) {
47-
currentUser.Planets.splice(index, 1, planet)
48-
return true
49-
}
50-
return false
51-
})
52-
if (isNew) currentUser.Planets.push(planet)
53-
54-
localStorage.setItem('currentUser', JSON.stringify(currentUser))
55-
UserStore.Actions.update(currentUser)
5645
this.props.transitionTo('planetHome', {userName: planet.userName, planetName: planet.name})
5746
this.props.close()
5847
}.bind(this))
@@ -61,14 +50,20 @@ module.exports = React.createClass({
6150
})
6251
},
6352
render: function () {
53+
var teamOptions = this.state.user.Teams.map(function (team) {
54+
return (
55+
<option value={team.name}>{team.profileName} ({team.name})</option>
56+
)
57+
})
6458
return (
6559
<div className='PlanetCreateModal modal'>
6660
<input ref='name' valueLink={this.linkState('planet.name')} className='nameInput stripInput' placeholder='Crate new Planet'/>
6761

6862
<div className='formField'>
6963
of
70-
<select valueLink={this.linkState('planet.OwnerId')}>
71-
<option value={this.state.user.id}>Me({this.state.user.name})</option>
64+
<select valueLink={this.linkState('ownerName')}>
65+
<option value={this.state.user.name}>Me({this.state.user.name})</option>
66+
{teamOptions}
7267
</select>
7368
as
7469
<select valueLink={this.linkState('planet.public')}>

browser/main/Components/PlanetSettingModal.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var React = require('react/addons')
2-
var Select = require('react-select')
32

43
var Catalyst = require('../Mixins/Catalyst')
54

browser/main/Components/PreferencesModal.jsx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,6 @@ module.exports = React.createClass({
3434
componentWillUnmount: function () {
3535
},
3636
onListen: function (res) {
37-
console.log(res)
38-
if (res.status === 'userProfileUpdated') {
39-
this.setState({
40-
isUpdatingProfile: false,
41-
isUpdatingProfileDone: true,
42-
isUpdatingProfileFailed: false
43-
})
44-
return
45-
}
46-
47-
if (res.status === 'userProfileUpdatingFailed') {
48-
this.setState({
49-
isUpdatingProfile: false,
50-
isUpdatingProfileDone: false,
51-
isUpdatingProfileFailed: true
52-
})
53-
return
54-
}
5537
},
5638
activeProfile: function () {
5739
this.setState({currentTab: 'profile'})
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* global localStorage */
2+
3+
var React = require('react/addons')
4+
5+
var Hq = require('../Services/Hq')
6+
7+
var LinkedState = require('../Mixins/LinkedState')
8+
9+
var UserStore = require('../Stores/UserStore')
10+
11+
module.exports = React.createClass({
12+
mixins: [LinkedState],
13+
propTypes: {
14+
user: React.PropTypes.shape({
15+
name: React.PropTypes.string
16+
}),
17+
transitionTo: React.PropTypes.func,
18+
close: React.PropTypes.func
19+
},
20+
getInitialState: function () {
21+
return {
22+
team: {
23+
name: ''
24+
}
25+
}
26+
},
27+
handleSubmit: function () {
28+
Hq.createTeam(this.props.user.name, this.state.team)
29+
.then(function (res) {
30+
var currentUser = JSON.parse(localStorage.getItem('currentUser'))
31+
var team = res.body
32+
33+
currentUser.Teams.push(team)
34+
localStorage.setItem('currentUser', JSON.stringify(currentUser))
35+
UserStore.Actions.update(currentUser)
36+
this.props.transitionTo('userHome', {userName: team.name})
37+
this.props.close()
38+
}.bind(this))
39+
.catch(function (err) {
40+
console.error(err)
41+
})
42+
},
43+
render: function () {
44+
return (
45+
<div className='TeamCreateModal modal'>
46+
<input valueLink={this.linkState('team.name')} className='nameInput stripInput' placeholder='Create new team'/>
47+
48+
<button onClick={this.handleSubmit} className='submitButton'>
49+
<i className='fa fa-check'/>
50+
</button>
51+
</div>
52+
)
53+
}
54+
})

browser/main/Containers/MainContainer.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ module.exports = React.createClass({
4040
if (this.isActive('root')) {
4141
if (localStorage.getItem('currentUser') == null) {
4242
this.transitionTo('login')
43+
return
4344
} else {
4445
this.transitionTo('home')
46+
return
4547
}
4648
}
4749

0 commit comments

Comments
 (0)