Support deleting feed

This commit is contained in:
Marcus Noble 2021-02-21 10:29:07 +00:00
parent ab390c9d47
commit 22db062fd9
4 changed files with 27 additions and 0 deletions

View File

@ -33,6 +33,11 @@ func (fs *FeedStore) GetFeed(id string) *Feed {
return feed
}
func (fs *FeedStore) DeleteFeed(id string) {
fs.getDB().Delete(Feed{ID: id})
fs.getDB().Unscoped().Delete(Item{}, "feed_id = ?", id)
}
func (fs *FeedStore) GetItem(id string) *Item {
item := &Item{}
fs.getDB().Where("id = ?", id).First(item)

View File

@ -17,6 +17,11 @@ func (a *API) GetFeed(c *fiber.Ctx) error {
return c.JSON(a.FeedStore.GetFeed(c.Params("id")))
}
func (a *API) DeleteFeed(c *fiber.Ctx) error {
a.FeedStore.DeleteFeed(c.Params("id"))
return nil
}
func (a *API) PostFeed(c *fiber.Ctx) error {
url := ""
if err := c.BodyParser(&url); err != nil {

View File

@ -50,6 +50,7 @@ func Start(port string) error {
app.Get("/api/feeds", api.GetFeeds)
app.Post("/api/feeds", api.PostFeed)
app.Get("/api/feed/:id", api.GetFeed)
app.Delete("/api/feed/:id", api.DeleteFeed)
app.Get("/api/item/:id", api.GetItem)
app.Post("/api/item/:id/save", api.SaveItem)
app.Get("/api/unread", api.GetUnread)

View File

@ -63,6 +63,11 @@
<div v-for="feed in feeds" :class="{strong: unreadCounts[feed.ID], 'alert': true, 'alert-success': selectedFeed == feed.ID }" :data-feed="feed.FeedURL" v-on:click="loadFeed(feed.ID)">
<img :src="feedIcon(feed)" style="height: 16px; width: 16px;" onerror="this.style.visibility = 'hidden'" /> {{feed.Title}} ({{unreadCounts[feed.ID] || '0'}})
<div style="float:right">
<button title="Delete Feed" v-on:click="deleteFeed(feed)" :disabled="isBusy">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="16px" width="16px" viewBox="0 0 473 473" enable-background="new 0 0 473 473"><g><path d="M317.7 214.4l5.6-86.4h21V38h-98.4V0H132.7v38H34.3v90h21l20 305h140.5a129.6 129.6 0 00223-89.4c0-68.6-53.7-124.8-121.1-129.2zM162.7 30h53.2v8h-53.2v-8zM64.3 68h250v30h-250V68zm39 335l-18-275h208l-5.8 88a129.6 129.6 0 00-93.2 187h-91zm206 40a99.5 99.5 0 010-198.9 99.5 99.5 0 010 198.9z"/><path d="M342.2 289.4l-33 33-32.9-33-21.2 21.2 33 33-33 33 21.2 21.1 33-33 33 33 21.2-21.2-33-33 33-32.9z"/></g><g/><g/><g/><g/><g/><g/><g/><g/><g/><g/><g/><g/><g/><g/><g/></svg>
</button>
</div>
</div>
<div :class="{ strong: items.length, alert: true, 'alert-success': selectedFeed == 'SAVED'}" v-on:click="loadFeed('SAVED')">
@ -222,6 +227,17 @@
showIframe(item) {
document.querySelector(`feed-item[item-id='${item.ID}'`).showIframe();
},
deleteFeed(feed) {
if (confirm(`Are you sure you want to remove '${feed.Title}'`)) {
this.setBusy(true);
fetch(`/api/feed/${feed.ID}`, {method: "DELETE"})
.then(() => {
this.feeds = this.feeds.filter(f => f.ID != feed.ID);
this.items = this.items.filter(i => i.FeedID != feed.ID);
this.setBusy(false);
});
}
},
nextItem() {
let currentItem = -1;
if (this.selectedItem != undefined) {