mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 18:56:22 +00:00
refactor modal & setup ordering for snippet
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/* global localStorage */
|
||||
var Reflux = require('reflux')
|
||||
var request = require('superagent')
|
||||
|
||||
@@ -6,6 +7,7 @@ var PlanetActions = require('../Actions/PlanetActions')
|
||||
var PlanetStore = Reflux.createStore({
|
||||
init: function () {
|
||||
this.listenTo(PlanetActions.fetchPlanet, this.fetchPlanet)
|
||||
this.listenTo(PlanetActions.createSnippet, this.createSnippet)
|
||||
},
|
||||
fetchPlanet: function (planetName) {
|
||||
request
|
||||
@@ -19,12 +21,32 @@ var PlanetStore = Reflux.createStore({
|
||||
}
|
||||
|
||||
var planet = res.body
|
||||
planet.Snippets = planet.Snippets.sort(function (a, b) {
|
||||
a = new Date(a.updatedAt)
|
||||
b = new Date(b.updatedAt)
|
||||
return a < b ? 1 : a > b ? -1 : 0
|
||||
})
|
||||
|
||||
this.trigger(planet)
|
||||
this.trigger({
|
||||
status: 'planetFetched',
|
||||
data: planet
|
||||
})
|
||||
}.bind(this))
|
||||
},
|
||||
updateSnippet: function (input) {
|
||||
|
||||
createSnippet: function (planetName, input) {
|
||||
request
|
||||
.post('http://localhost:8000/' + planetName + '/snippets')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + localStorage.getItem('token')
|
||||
})
|
||||
.send(input)
|
||||
.end(function (req, res) {
|
||||
console.log('snippet created', res.body)
|
||||
this.trigger({
|
||||
status: 'snippetCreated',
|
||||
data: res.body
|
||||
})
|
||||
}.bind(this))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user