1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-15 02:36:36 +00:00

add name change for planet & fix minor bugs

This commit is contained in:
Rokt33r
2015-07-23 07:55:56 +09:00
parent cdf6ed47dd
commit 2f754bbb87
11 changed files with 91 additions and 86 deletions

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.changeName, this.changeName)
this.listenTo(PlanetActions.addUser, this.addUser)
this.listenTo(PlanetActions.createSnippet, this.createSnippet)
this.listenTo(PlanetActions.updateSnippet, this.updateSnippet)
@@ -79,6 +80,38 @@ var PlanetStore = Reflux.createStore({
})
}.bind(this))
},
changeName: function (userName, planetName, name) {
request
.put(apiUrl + userName + '/' + planetName)
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
})
.send({name: name})
.end(function (err, res) {
if (err) {
console.error(err)
this.trigger(null)
return
}
var planet = res.body
var user = JSON.parse(localStorage.getItem('user'))
user.Planets.some(function (_planet, index) {
if (planet.id === _planet.id) {
user.Planets[index].name = planet.name
return true
}
return false
})
localStorage.setItem('user', JSON.stringify(user))
this.trigger({
status: 'nameChanged',
data: planet
})
}.bind(this))
},
addUser: function (planetName, userName) {
request
.post(apiUrl + planetName + '/users')