Skip to content

Commit

Permalink
feat: added a backend.AddItem abstract method
Browse files Browse the repository at this point in the history
  • Loading branch information
TypicalAM committed Jan 3, 2023
1 parent d9d1cef commit 21ebf74
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Backend interface {
// FetchArticles returns a tea.Cmd which gets the articles from
// the backend via a string key
FetchArticles(feedName string) tea.Cmd
// AddItem returns a tea.Cmd which adds an item to the rss
AddItem(tabType tab.Type, fields ...string)
// Close closes the backend
Close() error
}
Expand Down
4 changes: 4 additions & 0 deletions internal/backend/cache/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/TypicalAM/goread/internal/backend"
simpleList "github.com/TypicalAM/goread/internal/list"
"github.com/TypicalAM/goread/internal/rss"
"github.com/TypicalAM/goread/internal/tab"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
)
Expand Down Expand Up @@ -118,6 +119,9 @@ func (b Backend) FetchArticles(feedName string) tea.Cmd {
}
}

// AddItem adds an item to the rss
func (b Backend) AddItem(tabType tab.Type, fields ...string) {}

// Close closes the backend
func (b Backend) Close() error {
// Try to save the rss
Expand Down
4 changes: 4 additions & 0 deletions internal/backend/fake/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/TypicalAM/goread/internal/backend"
simpleList "github.com/TypicalAM/goread/internal/list"
"github.com/TypicalAM/goread/internal/rss"
"github.com/TypicalAM/goread/internal/tab"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/mmcdole/gofeed"
Expand Down Expand Up @@ -90,6 +91,9 @@ func (b Backend) FetchArticles(feedName string) tea.Cmd {
}
}

// AddItem adds an item to the rss
func (b Backend) AddItem(tabType tab.Type, fields ...string) {}

// Close the backend
func (b Backend) Close() error {
return nil
Expand Down
4 changes: 4 additions & 0 deletions internal/backend/web/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/TypicalAM/goread/internal/backend"
simpleList "github.com/TypicalAM/goread/internal/list"
"github.com/TypicalAM/goread/internal/rss"
"github.com/TypicalAM/goread/internal/tab"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/mmcdole/gofeed"
Expand Down Expand Up @@ -105,6 +106,9 @@ func (b Backend) FetchArticles(feedName string) tea.Cmd {
}
}

// AddItem adds an item to the rss
func (b Backend) AddItem(tabType tab.Type, fields ...string) {}

// Close closes the backend
func (b Backend) Close() error {
// Try to save the rss
Expand Down
3 changes: 2 additions & 1 deletion internal/model/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

if m.createItem.Index() == -1 {
m.creatingItem = false
m.message = "Ended " + strings.Join(m.createItem.GetValues(), " ")
m.backend.AddItem(m.createItem.Type, m.createItem.GetValues()...)
m.message = "Added an item - " + strings.Join(m.createItem.GetValues(), " ")
}

return m, tea.Batch(cmds...)
Expand Down

0 comments on commit 21ebf74

Please sign in to comment.