Skip to content

Commit

Permalink
refactor: ♻️ update styles and global constants go
Browse files Browse the repository at this point in the history
  • Loading branch information
dylantientcheu committed Dec 18, 2022
1 parent 9e62136 commit a9431d3
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 113 deletions.
7 changes: 7 additions & 0 deletions nba/global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package nba

var (
Gm *BoxScoreRepository
Sb *ScoreboardRepository
St *StandingsRepository
)
10 changes: 5 additions & 5 deletions nba/scoreboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/nleeper/goment"

"github.com/dylantientcheu/nbacli/nag"
"github.com/dylantientcheu/nbacli/styles"
"github.com/dylantientcheu/nbacli/ui/constants"
)

type BoxScoreSummary struct {
Expand Down Expand Up @@ -40,15 +40,15 @@ func (g BoxScoreSummary) Description() string {

// show time from now
desc = fmt.Sprintf("Tip-off %s | %s", moment.From(now), g.ArenaName)
desc = styles.DescStyle(desc)
desc = constants.DescStyle(desc)
} else if status == "Final" {
// passed game
// gameDate := GetDateFromString(g.GameDate).Format("2006-01-02")
desc = fmt.Sprintf("%s %s", styles.ScoreStyle(g.HomeTeamScore, g.VisitorTeamScore), styles.DescStyle(g.ArenaName))
desc = fmt.Sprintf("%s %s", constants.ScoreStyle(g.HomeTeamScore, g.VisitorTeamScore), constants.DescStyle(g.ArenaName))
} else {
// live game
desc = fmt.Sprintf("%s %s - %s | %s", styles.LiveStyle(), styles.ScoreStyle(g.HomeTeamScore, g.VisitorTeamScore), styles.DescStyle(status), styles.DescStyle(g.ArenaName))
desc = styles.DescText.Render(desc)
desc = fmt.Sprintf("%s %s - %s | %s", constants.LiveStyle(), constants.ScoreStyle(g.HomeTeamScore, g.VisitorTeamScore), constants.DescStyle(status), constants.DescStyle(g.ArenaName))
desc = constants.DescText.Render(desc)
}

return desc
Expand Down
83 changes: 0 additions & 83 deletions styles/constants.go

This file was deleted.

62 changes: 45 additions & 17 deletions ui/constants/consts.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package constants

import (
"github.com/dylantientcheu/nbacli/nba"
"strconv"

"github.com/evertras/bubble-table/table"

"github.com/charmbracelet/bubbles/key"
Expand All @@ -13,16 +14,12 @@ import (

var BaseStyle = lipgloss.NewStyle().
BorderStyle(lipgloss.RoundedBorder()).
BorderForeground(Accent)
BorderForeground(Secondary)

var (
// P the current tea program
P *tea.Program

Gm *nba.BoxScoreRepository
Sb *nba.ScoreboardRepository
St *nba.StandingsRepository

// WindowSize store the size of the terminal window
WindowSize tea.WindowSizeMsg

Expand All @@ -46,11 +43,21 @@ var (
InnerDivider: "│",
}

Accent = lipgloss.AdaptiveColor{Light: "#874BFD", Dark: "#7D56F4"}
LiveText = lipgloss.NewStyle().Background(lipgloss.AdaptiveColor{Light: "#ef2929", Dark: "#ef2929"}).Foreground(lipgloss.AdaptiveColor{Light: "#ffffff", Dark: "#ffffff"}).Bold(true)

FinalText = lipgloss.NewStyle().Background(lipgloss.Color("#9356DF")).Foreground(lipgloss.Color("#ffffff")).Bold(true)
DescText = lipgloss.NewStyle().Foreground(lipgloss.Color("#818181"))

ScoreText = lipgloss.NewStyle().Background(lipgloss.AdaptiveColor{Light: "214", Dark: "#181818"}).Foreground(lipgloss.AdaptiveColor{Light: "0", Dark: "214"})

Accent = lipgloss.AdaptiveColor{Light: "#5b1b7b", Dark: "#5b1b7b"}
AccentDarker = lipgloss.AdaptiveColor{Light: "#5b1b7b", Dark: "#5b1b7b"}
Secondary = lipgloss.AdaptiveColor{Light: "#ed2265", Dark: "#ed2265"}
Tertiary = lipgloss.AdaptiveColor{Light: "#f69053", Dark: "#f69053"}

activeTabBorder = lipgloss.Border{
Bottom: "─",
Top: "─",
Bottom: " ",
Left: "│",
Right: "│",
TopLeft: "╭",
Expand All @@ -60,24 +67,29 @@ var (
}

tabBorder = lipgloss.Border{
Top: "─",
Bottom: "─",
Left: "│",
Right: "│",
TopLeft: "╭",
TopRight: "╮",
BottomLeft: "",
BottomRight: "",
Bottom: "─",
// Top: "─",
// Left: "│",
// Right: "│",
// TopLeft: "╭",
// TopRight: "╮",
BottomLeft: "",
BottomRight: "",
}

TabStyle = lipgloss.NewStyle().
Border(tabBorder, true).
BorderForeground(Accent).
Background(Accent).
Foreground(lipgloss.Color("#FFFFFF")).
Padding(0, 1)

ActiveTabStyle = lipgloss.NewStyle().
Border(activeTabBorder, true).
BorderForeground(Accent).
BorderForeground(Secondary).
Background(Secondary).
Foreground(lipgloss.Color("#FFFFFF")).
Bold(true).
Padding(0, 1)

BleedSpaceWidth = 4
Expand Down Expand Up @@ -138,3 +150,19 @@ func Max(a, b int) int {
}
return b
}

func LiveStyle() string {
return LiveText.Render(" LIVE ")
}

func FinalStyle() string {
return FinalText.Render(" FINAL ")
}

func ScoreStyle(homeScore int, awayScore int) string {
return ScoreText.Render(" " + strconv.Itoa(homeScore) + " - " + strconv.Itoa(awayScore) + " ")
}

func DescStyle(desc string) string {
return DescText.Render(desc)
}
14 changes: 9 additions & 5 deletions ui/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func InitGameView(activeGameID string, activeGame nba.BoxScoreSummary, previousM
table.NewFlexColumn("PTS", "PTS", 3),
}

rows := newStatsBoard(constants.Gm, activeGameID)
rows := newStatsBoard(nba.Gm, activeGameID)

t := table.New(columns).WithRows(rows).
Focused(true).
Expand All @@ -126,7 +126,9 @@ func statsToRows(gameStats []nba.GameStat) []table.Row {
var rows []table.Row
areBenchers := false

rows = append(rows, table.NewRow(renderTeamRow("AWAY TEAM")).WithStyle(lipgloss.NewStyle().AlignHorizontal(lipgloss.Center).Background(lipgloss.AdaptiveColor{Light: "0", Dark: "214"})))
rows = append(rows, table.NewRow(renderTeamRow("AWAY TEAM")).
WithStyle(lipgloss.NewStyle().AlignHorizontal(lipgloss.Center).
Background(constants.Secondary)))

for idx, stat := range gameStats {
// format plus minus
Expand Down Expand Up @@ -166,7 +168,9 @@ func statsToRows(gameStats []nba.GameStat) []table.Row {
}

if idx < len(gameStats)-1 && gameStats[idx].TeamID != gameStats[idx+1].TeamID {
rows = append(rows, table.NewRow(renderTeamRow("HOME TEAM")).WithStyle(lipgloss.NewStyle().AlignHorizontal(lipgloss.Center).Background(lipgloss.AdaptiveColor{Light: "0", Dark: "214"})))
rows = append(rows, table.NewRow(renderTeamRow("HOME TEAM")).WithStyle(lipgloss.NewStyle().
AlignHorizontal(lipgloss.Center).
Background(constants.Secondary)))
}
}
return rows
Expand All @@ -175,7 +179,7 @@ func statsToRows(gameStats []nba.GameStat) []table.Row {
func renderBenchRow() table.RowData {
return table.RowData{
"POS": "",
"NAME": table.NewStyledCell("B E N C H", lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "0", Dark: "214"}).Padding(0)),
"NAME": table.NewStyledCell("B E N C H", lipgloss.NewStyle().Foreground(constants.Tertiary).Padding(0)),
"MIN": "",
"FG": "",
"3PT": "",
Expand All @@ -193,7 +197,7 @@ func renderBenchRow() table.RowData {
func renderTeamRow(team string) table.RowData {
return table.RowData{
"POS": "",
"NAME": table.NewStyledCell(team, lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "214", Dark: "0"})),
"NAME": table.NewStyledCell(team, lipgloss.NewStyle().Foreground(lipgloss.Color("#FFFFFF"))),
"MIN": "",
"FG": "",
"3PT": "",
Expand Down
2 changes: 1 addition & 1 deletion ui/scoreboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Model struct {
}

func InitScoreboard(date time.Time) tea.Model {
items := newScoreboardList(constants.Sb, date)
items := newScoreboardList(nba.Sb, date)
m := Model{mode: nav, currentDate: date, list: list.NewModel(items, list.NewDefaultDelegate(), 8, 8)}
if constants.WindowSize.Height != 0 {
top, right, bottom, left := constants.DocStyle.GetMargin()
Expand Down
2 changes: 1 addition & 1 deletion ui/standings.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func InitStandingsView() *StandingsModel {
table.NewFlexColumn("L10", "L10", 3),
}

easternRows, westernRows := newStandingsBoard(constants.St)
easternRows, westernRows := newStandingsBoard(nba.St)

tEast := table.New(columns).WithRows(easternRows).Focused(true).Border(constants.CustomTableBorder).WithBaseStyle(constants.BaseStyle).WithPageSize(10)
tWest := table.New(columns).WithRows(westernRows).Border(constants.CustomTableBorder).WithBaseStyle(constants.BaseStyle).WithPageSize(10)
Expand Down
2 changes: 1 addition & 1 deletion ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func StartTea(date time.Time) {
}
}()
}
constants.Sb = &scbrd
nba.Sb = &scbrd

m := InitScoreboard(date)
UpdateTeaView(m)
Expand Down

0 comments on commit a9431d3

Please sign in to comment.