1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

add delete planet request

This commit is contained in:
Rokt33r
2015-07-25 12:39:09 +09:00
parent 4df489bd10
commit 5dbfb24f1c
5 changed files with 51 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ var Reflux = require('reflux')
module.exports = Reflux.createActions([
'createPlanet',
'fetchPlanet',
'deletePlanet',
'changeName',
'addUser',

View File

@@ -66,7 +66,7 @@ module.exports = React.createClass({
},
doubleCheckDeletePlanet: function () {
if (this.state.isDeletePlanetChecked) {
console.log('delete it')
PlanetActions.deletePlanet(this.props.currentPlanet.userName, this.props.currentPlanet.name)
return
}
this.setState({isDeletePlanetChecked: true})

View File

@@ -224,8 +224,9 @@ module.exports = React.createClass({
var articles = this.state.currentPlanet == null ? null : this.state.currentPlanet.Articles
var planet
if (res.status === 'planetFetched') {
var planet = res.data
planet = res.data
this.setState({isFetched: true, currentPlanet: planet, filteredArticles: planet.Articles}, function () {
if (this.refs.detail.props.article == null) {
var params = this.props.params
@@ -248,6 +249,14 @@ module.exports = React.createClass({
return
}
if (res.status === 'planetDeleted') {
planet = res.data
this.transitionTo('user', {
userName: this.props.params.userName
})
return
}
var user
if (res.status === 'userAdded') {
user = res.data

View File

@@ -58,20 +58,38 @@ module.exports = React.createClass({
onListen: function (res) {
if (res == null || res.status == null) return
if (res.status === 'planetCreated') {
var currentUser = this.state.currentUser
if (res.status === 'planetCreated') {
currentUser.Planets.push(res.data)
localStorage.setItem('user', JSON.stringify(currentUser))
this.setState({currentUser: currentUser})
return
}
if (res.status === 'planetDeleted') {
currentUser.Planets.some(function (_planet, index) {
if (res.data.id === _planet.id) {
currentUser.Planets.splice(index, 1)
return true
}
return false
})
localStorage.setItem('user', JSON.stringify(currentUser))
this.setState({currentUser: currentUser})
return
}
if (res.status === 'nameChanged') {
this.setState({currentUser: AuthStore.getUser()})
return
}
if (res.status === 'userProfileUpdated') {
this.setState({currentUser: AuthStore.getUser()})
return
}
},
render: function () {

View File

@@ -10,6 +10,7 @@ var PlanetStore = Reflux.createStore({
init: function () {
this.listenTo(PlanetActions.createPlanet, this.createPlanet)
this.listenTo(PlanetActions.fetchPlanet, this.fetchPlanet)
this.listenTo(PlanetActions.deletePlanet, this.deletePlanet)
this.listenTo(PlanetActions.changeName, this.changeName)
this.listenTo(PlanetActions.addUser, this.addUser)
this.listenTo(PlanetActions.removeUser, this.removeUser)
@@ -81,6 +82,25 @@ var PlanetStore = Reflux.createStore({
})
}.bind(this))
},
deletePlanet: function (userName, planetName) {
request
.del(apiUrl + userName + '/' + planetName)
.send()
.end(function (err, res) {
if (err) {
console.error(err)
this.trigger(null)
return
}
var planet = res.body
this.trigger({
status: 'planetDeleted',
data: planet
})
}.bind(this))
},
changeName: function (userName, planetName, name) {
request
.put(apiUrl + userName + '/' + planetName)