From 9cd48c660231592f3f8d9a035d45b568d987616e Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 17 Apr 2025 17:46:39 +0200 Subject: Show icon for win/lose/draw on play landing page --- pkg/ui/views/play_util.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'pkg/ui/views/play_util.go') diff --git a/pkg/ui/views/play_util.go b/pkg/ui/views/play_util.go index c57f331..b2f70b5 100644 --- a/pkg/ui/views/play_util.go +++ b/pkg/ui/views/play_util.go @@ -21,7 +21,13 @@ func (m *PlayModel) handleError(msg error) (tea.Model, tea.Cmd) { return m, nil } -func formatGamesForPage(games []database.Game, altCodeStyle lipgloss.Style) []string { +var ( + winIcon = lipgloss.NewStyle().Foreground(lipgloss.Color("#f1c40f")).Render("🏆") + loseIcon = lipgloss.NewStyle().Foreground(lipgloss.Color("#895129")).Render("💩") + drawIcon = lipgloss.NewStyle().Foreground(lipgloss.Color("#bdc3c7")).Render("🤝") +) + +func formatGamesForPage(userID int, games []database.Game, altCodeStyle lipgloss.Style) []string { var gamesStrings []string gamesStrings = append(gamesStrings, "Games list") @@ -34,6 +40,28 @@ func formatGamesForPage(games []database.Game, altCodeStyle lipgloss.Style) []st for i, game := range games { indexStr := altCodeStyle.Render(fmt.Sprintf("[%d] ", i)) + icon := " " + + if game.Outcome != "*" { + if len(game.Outcome) >= 2 { + if game.Outcome[0:2] == "1-" { + if game.Player1.ID == userID { + icon = winIcon + } else { + icon = loseIcon + } + } else if game.Outcome[0:2] == "0-" { + if game.Player2 != nil && game.Player2.ID == userID { + icon = winIcon + } else { + icon = loseIcon + } + } else { + icon = drawIcon + } + } + } + nameStr := game.Name dateStr := game.UpdatedAt.Format("2006-01-02 15:04") @@ -44,6 +72,7 @@ func formatGamesForPage(games []database.Game, altCodeStyle lipgloss.Style) []st indexStr, nameStr, paddingStr, + icon, lipgloss.NewStyle().Foreground(lipgloss.Color("#d35400")).Render(dateStr), ) gamesStrings = append(gamesStrings, line) -- cgit v1.2.3-18-g5258