mirror of
https://github.com/nkanaev/yarr.git
synced 2025-09-13 09:55:36 +00:00
some work
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user