Skip to content

Commit 2f754bb

Browse files
committed
add name change for planet & fix minor bugs
1 parent cdf6ed4 commit 2f754bb

11 files changed

Lines changed: 91 additions & 86 deletions

browser/main/Actions/PlanetActions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = Reflux.createActions([
44
'createPlanet',
55
'fetchPlanet',
66

7+
'changeName',
78
'addUser',
89

910
'createSnippet',

browser/main/Components/BlueprintDeleteModal.jsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
var React = require('react')
2-
var PlanetStore = require('../Stores/PlanetStore')
2+
33
var PlanetActions = require('../Actions/PlanetActions')
44

55
var BlueprintDeleteModal = React.createClass({
66
propTypes: {
77
close: React.PropTypes.func,
88
blueprint: React.PropTypes.object
99
},
10-
componentDidMount: function () {
11-
this.unsubscribe = PlanetStore.listen(this.onListen)
12-
React.findDOMNode(this.refs.submit).focus()
13-
},
14-
componentWillUnmount: function () {
15-
this.unsubscribe()
16-
},
17-
onListen: function (res) {
18-
switch (res.status) {
19-
case 'articleDeleted':
20-
this.props.close()
21-
break
22-
}
23-
},
2410
stopPropagation: function (e) {
2511
e.stopPropagation()
2612
},

browser/main/Components/BlueprintEditModal.jsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
var React = require('react')
2+
23
var BlueprintForm = require('./BlueprintForm')
3-
var PlanetStore = require('../Stores/PlanetStore')
44

55
var BlueprintEditModal = React.createClass({
66
propTypes: {
77
close: React.PropTypes.func,
88
blueprint: React.PropTypes.object
99
},
10-
componentDidMount: function () {
11-
this.unsubscribe = PlanetStore.listen(this.onListen)
12-
},
13-
componentWillUnmount: function () {
14-
this.unsubscribe()
15-
},
16-
onListen: function (res) {
17-
switch (res.status) {
18-
case 'articleUpdated':
19-
this.props.close()
20-
break
21-
}
22-
},
2310
stopPropagation: function (e) {
2411
e.stopPropagation()
2512
},

browser/main/Components/LaunchModal.jsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
var React = require('react/addons')
22
var ReactRouter = require('react-router')
33
var Catalyst = require('../Mixins/Catalyst')
4-
var PlanetStore = require('../Stores/PlanetStore')
54

65
var SnippetForm = require('./SnippetForm')
76
var BlueprintForm = require('./BlueprintForm')
@@ -16,19 +15,6 @@ var LaunchModal = React.createClass({
1615
currentTab: 'snippet'
1716
}
1817
},
19-
componentDidMount: function () {
20-
this.unsubscribe = PlanetStore.listen(this.onListen)
21-
},
22-
componentWillUnmount: function () {
23-
this.unsubscribe()
24-
},
25-
onListen: function (res) {
26-
switch (res.status) {
27-
case 'articleCreated':
28-
this.props.close()
29-
break
30-
}
31-
},
3218
stopPropagation: function (e) {
3319
e.stopPropagation()
3420
},

browser/main/Components/PlanetSettingModal.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
var React = require('react/addons')
22
var Select = require('react-select')
3+
34
var Catalyst = require('../Mixins/Catalyst')
45

6+
var PlanetActions = require('../Actions/PlanetActions')
7+
58
module.exports = React.createClass({
69
mixins: [Catalyst.LinkedStateMixin],
710
propTypes: {
@@ -22,6 +25,10 @@ module.exports = React.createClass({
2225
activeManageMember: function () {
2326
this.setState({currentTab: 'manageMember'})
2427
},
28+
saveProfile: function () {
29+
var currentPlanet = this.props.currentPlanet
30+
PlanetActions.changeName(currentPlanet.userName, currentPlanet.name, this.state.planetName)
31+
},
2532
doubleCheckDeletePlanet: function () {
2633
if (this.state.isDeletePlanetChecked) {
2734
console.log('delete it')
@@ -44,7 +51,7 @@ module.exports = React.createClass({
4451
<div className='planetProfileForm'>
4552
<label>Planet name </label>
4653
<input valueLink={this.linkState('planetName')} className='inline-input'/>
47-
<button className='saveButton btn-primary'>Save</button>
54+
<button onClick={this.saveProfile} className='saveButton btn-primary'>Save</button>
4855
</div>
4956

5057
<div className='planetDeleteForm'>

browser/main/Components/SnippetDeleteModal.jsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
var React = require('react')
2-
var PlanetStore = require('../Stores/PlanetStore')
2+
33
var PlanetActions = require('../Actions/PlanetActions')
44

55
var SnippetDeleteModal = React.createClass({
66
propTypes: {
77
close: React.PropTypes.func,
88
snippet: React.PropTypes.object
99
},
10-
componentDidMount: function () {
11-
this.unsubscribe = PlanetStore.listen(this.onListen)
12-
React.findDOMNode(this.refs.submit).focus()
13-
},
14-
componentWillUnmount: function () {
15-
this.unsubscribe()
16-
},
17-
onListen: function (res) {
18-
switch (res.status) {
19-
case 'articleDeleted':
20-
this.props.close()
21-
break
22-
}
23-
},
2410
stopPropagation: function (e) {
2511
e.stopPropagation()
2612
},

browser/main/Components/SnippetEditModal.jsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
11
var React = require('react')
22
var SnippetForm = require('./SnippetForm')
3-
var PlanetStore = require('../Stores/PlanetStore')
43

54
var SnippetEditModal = React.createClass({
65
propTypes: {
76
close: React.PropTypes.func,
87
snippet: React.PropTypes.object
98
},
10-
componentDidMount: function () {
11-
this.unsubscribe = PlanetStore.listen(this.onListen)
12-
},
13-
componentWillUnmount: function () {
14-
this.unsubscribe()
15-
},
16-
onListen: function (res) {
17-
switch (res.status) {
18-
case 'articleUpdated':
19-
this.props.close()
20-
break
21-
}
22-
},
239
stopPropagation: function (e) {
2410
e.stopPropagation()
2511
},

browser/main/Components/UserNavigator.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = React.createClass({
3737
var planets = this.props.currentUser.Planets.map(function (planet, index) {
3838
return (
3939
<li key={planet.id} className={this.props.currentPlanet != null && this.props.currentPlanet.name === planet.name ? 'active' : ''}>
40-
<Link to='planet' params={{userName: this.props.currentUser.name, planetName: planet.name}} href>{planet.name[0]}</Link>
40+
<Link to='planet' params={{userName: planet.userName, planetName: planet.name}} href>{planet.name[0]}</Link>
4141
<div className='shortCut'>{index + 1}</div>
4242
</li>
4343
)

browser/main/Containers/PlanetContainer.jsx

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = React.createClass({
7070
this.unsubscribe()
7171
},
7272
componentDidUpdate: function () {
73-
if (this.state.currentPlanet.name !== this.props.params.planetName || this.state.currentPlanet.userName !== this.props.params.userName) {
73+
if (this.state.currentPlanet == null || this.state.currentPlanet.name !== this.props.params.planetName || this.state.currentPlanet.userName !== this.props.params.userName) {
7474
PlanetActions.fetchPlanet(this.props.params.userName, this.props.params.planetName)
7575
this.focus()
7676
}
@@ -162,6 +162,10 @@ module.exports = React.createClass({
162162
}
163163
},
164164
onFetched: function (res) {
165+
if (res == null) {
166+
return
167+
}
168+
165169
var articles = this.state.currentPlanet == null ? null : this.state.currentPlanet.Articles
166170

167171
if (res.status === 'planetFetched') {
@@ -195,8 +199,16 @@ module.exports = React.createClass({
195199
}
196200
this.state.currentPlanet.Users.push(user)
197201
this.setState({currentPlanet: this.state.currentPlanet}, function () {
198-
this.closeAddUserModal()
202+
if (this.state.isAddUserModalOpen) {this.closeAddUserModal()}
199203
})
204+
return
205+
}
206+
207+
if (res.status === 'nameChanged') {
208+
var params = Object.assign({}, this.props.params)
209+
params.planetName = res.data.name
210+
this.transitionTo('planet', params)
211+
return
200212
}
201213

202214
var article = res.data
@@ -209,14 +221,17 @@ module.exports = React.createClass({
209221
articles.unshift(article)
210222

211223
this.setState({planet: this.state.currentPlanet, search: ''}, function () {
224+
this.closeLaunchModal()
212225
this.selectArticleByIndex(0)
213226
})
214227
break
215228
case 'articleUpdated':
216229
articles.splice(index, 1)
217230
articles.unshift(article)
218231

219-
this.setState({planet: this.state.currentPlanet})
232+
this.setState({planet: this.state.currentPlanet}, function () {
233+
this.closeEditModal()
234+
})
220235
break
221236
case 'articleDeleted':
222237
articles.splice(index, 1)
@@ -241,20 +256,26 @@ module.exports = React.createClass({
241256
this.setState({isLaunchModalOpen: true})
242257
},
243258
closeLaunchModal: function () {
244-
this.setState({isLaunchModalOpen: false})
259+
this.setState({isLaunchModalOpen: false}, function () {
260+
this.focus()
261+
})
245262
},
246263
openAddUserModal: function () {
247264
this.setState({isAddUserModalOpen: true})
248265
},
249266
closeAddUserModal: function () {
250-
this.setState({isAddUserModalOpen: false})
267+
this.setState({isAddUserModalOpen: false}, function () {
268+
this.focus()
269+
})
251270
},
252271
openEditModal: function () {
253272
if (this.refs.detail.props.article == null) {return}
254273
this.setState({isEditModalOpen: true})
255274
},
256275
closeEditModal: function () {
257-
this.setState({isEditModalOpen: false})
276+
this.setState({isEditModalOpen: false}, function () {
277+
this.focus()
278+
})
258279
},
259280
submitEditModal: function () {
260281
this.setState({isEditModalOpen: false})
@@ -264,7 +285,9 @@ module.exports = React.createClass({
264285
this.setState({isDeleteModalOpen: true})
265286
},
266287
closeDeleteModal: function () {
267-
this.setState({isDeleteModalOpen: false})
288+
this.setState({isDeleteModalOpen: false}, function () {
289+
this.focus()
290+
})
268291
},
269292
submitDeleteModal: function () {
270293
this.setState({isDeleteModalOpen: false})
@@ -273,7 +296,9 @@ module.exports = React.createClass({
273296
this.setState({isSettingModalOpen: true})
274297
},
275298
closeSettingModal: function () {
276-
this.setState({isSettingModalOpen: false})
299+
this.setState({isSettingModalOpen: false}, function () {
300+
this.focus()
301+
})
277302
},
278303
focus: function () {
279304
React.findDOMNode(this).focus()
@@ -283,28 +308,30 @@ module.exports = React.createClass({
283308
if (this.state.isLaunchModalOpen) {
284309
if (e.keyCode === 27) {
285310
this.closeLaunchModal()
286-
this.focus()
287311
}
288312
return
289313
}
290314
if (this.state.isEditModalOpen) {
291315
if (e.keyCode === 27) {
292316
this.closeEditModal()
293-
this.focus()
294317
}
295318
return
296319
}
297320
if (this.state.isDeleteModalOpen) {
298321
if (e.keyCode === 27) {
299322
this.closeDeleteModal()
300-
this.focus()
301323
}
302324
return
303325
}
304326
if (this.state.isAddUserModalOpen) {
305327
if (e.keyCode === 27) {
306328
this.closeAddUserModal()
307-
this.focus()
329+
}
330+
return
331+
}
332+
if (this.state.isSettingModalOpen) {
333+
if (e.keyCode === 27) {
334+
this.closeSettingModal()
308335
}
309336
return
310337
}

browser/main/Containers/UserContainer.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ module.exports = React.createClass({
2727
this.unsubscribe()
2828
},
2929
onListen: function (res) {
30+
if (res.status == null) return
31+
3032
if (res.status === 'planetCreated') {
3133
var currentUser = this.state.currentUser
3234
currentUser.Planets.push(res.data)
3335

3436
localStorage.setItem('user', JSON.stringify(currentUser))
3537
this.setState({currentUser: currentUser})
3638
}
39+
40+
if (res.status === 'nameChanged') {
41+
this.setState({currentUser: AuthStore.getUser()})
42+
}
3743
},
3844
render: function () {
3945
var currentPlanetName = this.props.params.planetName

0 commit comments

Comments
 (0)