Skip to content

Commit 5dbfb24

Browse files
committed
add delete planet request
1 parent 4df489b commit 5dbfb24

5 files changed

Lines changed: 51 additions & 3 deletions

File tree

browser/main/Actions/PlanetActions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var Reflux = require('reflux')
33
module.exports = Reflux.createActions([
44
'createPlanet',
55
'fetchPlanet',
6+
'deletePlanet',
67

78
'changeName',
89
'addUser',

browser/main/Components/PlanetSettingModal.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module.exports = React.createClass({
6666
},
6767
doubleCheckDeletePlanet: function () {
6868
if (this.state.isDeletePlanetChecked) {
69-
console.log('delete it')
69+
PlanetActions.deletePlanet(this.props.currentPlanet.userName, this.props.currentPlanet.name)
7070
return
7171
}
7272
this.setState({isDeletePlanetChecked: true})

browser/main/Containers/PlanetContainer.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,9 @@ module.exports = React.createClass({
224224

225225
var articles = this.state.currentPlanet == null ? null : this.state.currentPlanet.Articles
226226

227+
var planet
227228
if (res.status === 'planetFetched') {
228-
var planet = res.data
229+
planet = res.data
229230
this.setState({isFetched: true, currentPlanet: planet, filteredArticles: planet.Articles}, function () {
230231
if (this.refs.detail.props.article == null) {
231232
var params = this.props.params
@@ -248,6 +249,14 @@ module.exports = React.createClass({
248249
return
249250
}
250251

252+
if (res.status === 'planetDeleted') {
253+
planet = res.data
254+
this.transitionTo('user', {
255+
userName: this.props.params.userName
256+
})
257+
return
258+
}
259+
251260
var user
252261
if (res.status === 'userAdded') {
253262
user = res.data

browser/main/Containers/UserContainer.jsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,38 @@ module.exports = React.createClass({
5858
onListen: function (res) {
5959
if (res == null || res.status == null) return
6060

61+
var currentUser = this.state.currentUser
62+
6163
if (res.status === 'planetCreated') {
62-
var currentUser = this.state.currentUser
6364
currentUser.Planets.push(res.data)
6465

6566
localStorage.setItem('user', JSON.stringify(currentUser))
6667
this.setState({currentUser: currentUser})
68+
return
69+
}
70+
71+
if (res.status === 'planetDeleted') {
72+
currentUser.Planets.some(function (_planet, index) {
73+
if (res.data.id === _planet.id) {
74+
currentUser.Planets.splice(index, 1)
75+
return true
76+
}
77+
return false
78+
})
79+
80+
localStorage.setItem('user', JSON.stringify(currentUser))
81+
this.setState({currentUser: currentUser})
82+
return
6783
}
6884

6985
if (res.status === 'nameChanged') {
7086
this.setState({currentUser: AuthStore.getUser()})
87+
return
7188
}
7289

7390
if (res.status === 'userProfileUpdated') {
7491
this.setState({currentUser: AuthStore.getUser()})
92+
return
7593
}
7694
},
7795
render: function () {

browser/main/Stores/PlanetStore.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var PlanetStore = Reflux.createStore({
1010
init: function () {
1111
this.listenTo(PlanetActions.createPlanet, this.createPlanet)
1212
this.listenTo(PlanetActions.fetchPlanet, this.fetchPlanet)
13+
this.listenTo(PlanetActions.deletePlanet, this.deletePlanet)
1314
this.listenTo(PlanetActions.changeName, this.changeName)
1415
this.listenTo(PlanetActions.addUser, this.addUser)
1516
this.listenTo(PlanetActions.removeUser, this.removeUser)
@@ -81,6 +82,25 @@ var PlanetStore = Reflux.createStore({
8182
})
8283
}.bind(this))
8384
},
85+
deletePlanet: function (userName, planetName) {
86+
request
87+
.del(apiUrl + userName + '/' + planetName)
88+
.send()
89+
.end(function (err, res) {
90+
if (err) {
91+
console.error(err)
92+
this.trigger(null)
93+
return
94+
}
95+
96+
var planet = res.body
97+
98+
this.trigger({
99+
status: 'planetDeleted',
100+
data: planet
101+
})
102+
}.bind(this))
103+
},
84104
changeName: function (userName, planetName, name) {
85105
request
86106
.put(apiUrl + userName + '/' + planetName)

0 commit comments

Comments
 (0)