Skip to content

Commit

Permalink
feat: return to menu from the leaderboard; show leaderboard help (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Broderick-Westrope authored Aug 19, 2024
1 parent 89c3f9e commit 91d2c34
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/tetrigo/leaderboard/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/Broderick-Westrope/tetrigo/cmd/tetrigo/common"
"github.com/Broderick-Westrope/tetrigo/internal/data"
"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
Expand All @@ -14,6 +15,7 @@ import (

type Model struct {
keys *keyMap
help help.Model

repo *data.LeaderboardRepository
table table.Model
Expand Down Expand Up @@ -42,6 +44,7 @@ func NewModel(in *common.LeaderboardInput, db *sql.DB) (Model, error) {

return Model{
keys: defaultKeyMap(),
help: help.New(),
repo: repo,
table: getLeaderboardTable(scores, newEntryID),
}, nil
Expand All @@ -53,8 +56,11 @@ func (m Model) Init() tea.Cmd {

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg, ok := msg.(tea.KeyMsg); ok {
if key.Matches(msg, m.keys.Exit) {
return m, tea.Quit
switch {
case key.Matches(msg, m.keys.Exit):
return m, common.SwitchModeCmd(common.ModeMenu, common.NewMenuInput())
case key.Matches(msg, m.keys.Help):
m.help.ShowAll = !m.help.ShowAll
}
}

Expand All @@ -64,7 +70,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m Model) View() string {
return m.table.View() + "\n"
return m.table.View() + "\n" + m.help.View(m.keys)
}

func getLeaderboardTable(scores []data.Score, focusID int) table.Model {
Expand Down

0 comments on commit 91d2c34

Please sign in to comment.