ui: create new feed

This commit is contained in:
Nazar Kanaev
2020-07-01 17:22:06 +01:00
parent 14781476e0
commit 866d59fe86
3 changed files with 63 additions and 19 deletions

View File

@@ -0,0 +1,25 @@
"use strict";
(function() {
var api = function(method, endpoint, data) {
var promise = fetch(endpoint, {
method: method,
headers: {'content-type': 'application/json'},
body: JSON.stringify(data),
})
return promise.then(function(res) {
if (res.ok) return res.json()
})
}
window.api = {
feeds: {
list: function() {
return api('get', '/api/feeds')
},
create: function(data) {
return api('post', '/api/feeds', data)
},
}
}
})()

View File

@@ -32,6 +32,7 @@ var vm = new Vue({
'itemSelected': null,
'settings': 'manage',
'newFolderTitle': null,
'loading': {newfeed: 0},
}
},
computed: {
@@ -95,5 +96,20 @@ var vm = new Vue({
this.feeds = this.feeds.filter(function(f) { f.id != feed.id })
}
},
createFeed: function(event) {
var form = event.target
var data = {
url: form.querySelector('input[name=url]').value,
folder_id: parseInt(form.querySelector('select[name=folder_id]').value) || null,
}
this.loading.newfeed = true
var vm = this
api.feeds.create(data).then(function(result) {
if (result.status === 'success') {
vm.$bvModal.hide('settings-modal')
}
vm.loading.newfeed = false
})
},
}
})