Skip to content

Commit

Permalink
feat: favorite within post (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsloth55 authored Dec 31, 2024
1 parent 1ecde16 commit 3a88b21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/commands/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ViewportKeyMapT struct {
Quit key.Binding
Escape key.Binding
OpenInBrowser key.Binding
Favourite key.Binding
GotoStart key.Binding
GotoEnd key.Binding
Next key.Binding
Expand Down Expand Up @@ -140,6 +141,10 @@ var ViewportKeyMap = ViewportKeyMapT{
key.WithKeys("o"),
key.WithHelp("o", "open in browser"),
),
Favourite: key.NewBinding(
key.WithKeys("f"),
key.WithHelp("f", "favourite"),
),
GotoStart: key.NewBinding(
key.WithKeys("g", "home"),
key.WithHelp("g", "top"),
Expand All @@ -164,7 +169,7 @@ func (k ViewportKeyMapT) FullHelp() [][]key.Binding {
return [][]key.Binding{
{v.Up, v.Down, v.HalfPageUp, v.HalfPageDown},
{k.GotoStart, k.GotoEnd, v.PageUp, v.PageDown},
{k.Next, k.Prev, k.OpenInBrowser},
{k.Next, k.Prev, k.OpenInBrowser, k.Favourite},
{k.Escape, k.Quit, k.CloseFullHelp},
}
}
Expand Down
11 changes: 11 additions & 0 deletions internal/commands/viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ func updateViewport(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
cmd = m.commands.OpenLink(it.URL)
cmds = append(cmds, cmd)

case key.Matches(msg, ViewportKeyMap.Favourite):
current, err := m.commands.store.GetItemByID(*m.selectedArticle)
if err != nil {
return m, nil
}
err = m.commands.store.ToggleFavourite(current.ID)
if err != nil {
return m, tea.Quit
}
cmds = append(cmds, m.UpdateList())

case key.Matches(msg, ViewportKeyMap.Prev):
current := m.list.Index()
if current-1 < 0 {
Expand Down

0 comments on commit 3a88b21

Please sign in to comment.