some work
This commit is contained in:
parent
e72956ebac
commit
8ed55fe1e7
3 changed files with 41 additions and 14 deletions
|
|
@ -2,28 +2,32 @@
|
|||
|
||||
(function() {
|
||||
var api = function(method, endpoint, data) {
|
||||
var promise = fetch(endpoint, {
|
||||
return fetch(endpoint, {
|
||||
method: method,
|
||||
headers: {'content-type': 'application/json'},
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
return promise.then(function(res) {
|
||||
if (res.ok) return res.json()
|
||||
})
|
||||
}
|
||||
|
||||
var json = function(res) {
|
||||
return res.json()
|
||||
}
|
||||
|
||||
window.api = {
|
||||
feeds: {
|
||||
list: function() {
|
||||
return api('get', '/api/feeds')
|
||||
return api('get', '/api/feeds').then(json)
|
||||
},
|
||||
create: function(data) {
|
||||
return api('post', '/api/feeds', data)
|
||||
return api('post', '/api/feeds', data).then(json)
|
||||
},
|
||||
delete: function(id) {
|
||||
return api('delete', '/api/feeds/' + id)
|
||||
}
|
||||
},
|
||||
folders: {
|
||||
list: function() {
|
||||
return api('get', '/api/folders')
|
||||
return api('get', '/api/folders').then(json)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,12 @@ var vm = new Vue({
|
|||
},
|
||||
deleteFeed: function(feed) {
|
||||
if (confirm('Are you sure you want to delete ' + feed.title + '?')) {
|
||||
this.feeds = this.feeds.filter(function(f) { f.id != feed.id })
|
||||
var vm = this
|
||||
api.feeds.delete(feed.id).then(function() {
|
||||
api.feeds.list().then(function(feeds) {
|
||||
vm.feeds = feeds
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
createFeed: function(event) {
|
||||
|
|
@ -102,6 +107,9 @@ var vm = new Vue({
|
|||
var vm = this
|
||||
api.feeds.create(data).then(function(result) {
|
||||
if (result.status === 'success') {
|
||||
api.feeds.list().then(function(feeds) {
|
||||
vm.feeds = feeds
|
||||
})
|
||||
vm.$bvModal.hide('settings-modal')
|
||||
}
|
||||
vm.loading.newfeed = false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue