Skip to content

Commit

Permalink
Changed string key to mapping key template
Browse files Browse the repository at this point in the history
  • Loading branch information
grrlopes committed Aug 27, 2023
1 parent d5a5c6f commit 54df93e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions helper/keymaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var HotKeysHome = Keymap{
),
MoveUp: key.NewBinding(
key.WithKeys("shift+tab", "up", "j"),
key.WithHelp("tab/Up", "↑"),
key.WithHelp("shift+tab/Up", "↑"),
),
MoveDown: key.NewBinding(
key.WithKeys("tab", "down", "k"),
Expand All @@ -88,8 +88,8 @@ var HotKeysFinder = Keymap{
var HotKeysSync = Keymap{
Enter: HotKeysHome.Enter,
Quit: key.NewBinding(
key.WithKeys("ctrl+c"),
key.WithHelp("ctrl+c", "quit"),
key.WithKeys("ctrl+c", "q"),
key.WithHelp("ctrl+c/q", "quit"),
),
MoveLeft: key.NewBinding(
key.WithKeys("left"),
Expand Down
12 changes: 7 additions & 5 deletions ui/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"fmt"
"time"

"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/grrlopes/storydb/helper"
"github.com/grrlopes/storydb/usecase/fhistory"
)

Expand All @@ -29,16 +31,16 @@ func syncUpdate(msg tea.Msg, m ModelHome) (*ModelHome, tea.Cmd) {

switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "left":
switch {
case key.Matches(msg, helper.HotKeysSync.MoveLeft):
m.home.StatusSyncScreen = true
m.home.Viewport.SetContent(syncView(&m))
return &m, nil
case "right":
case key.Matches(msg, helper.HotKeysSync.MoveRight):
m.home.StatusSyncScreen = false
m.home.Viewport.SetContent(syncView(&m))
return &m, nil
case "enter":
case key.Matches(msg, helper.HotKeysSync.Enter):
if m.home.StatusSyncScreen {
choiceEntered = "syncing"
cmds = append(cmds, syncTickCmd())
Expand All @@ -47,7 +49,7 @@ func syncUpdate(msg tea.Msg, m ModelHome) (*ModelHome, tea.Cmd) {
}
m.home.StatusSyncScreen = false
return &m, tea.Batch(cmds...)
case "q", "ctrl+c":
case key.Matches(msg, helper.HotKeysSync.Quit):
if m.home.ActiveSyncScreen {
m.home.ActiveSyncScreen = false
m.home.Viewport.SetContent(m.GetDataView())
Expand Down

0 comments on commit 54df93e

Please sign in to comment.