summaryrefslogtreecommitdiff
path: root/pkg/ui/views/play_util.go
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2025-04-17 17:46:39 +0200
committerSanto Cariotti <santo@dcariotti.me>2025-04-17 17:46:39 +0200
commit9cd48c660231592f3f8d9a035d45b568d987616e (patch)
tree5d6adb401f1697a78230f9931e9682be30cbdf95 /pkg/ui/views/play_util.go
parent3ad0d21e072c7461ea78a9a85111e6e19d3b0632 (diff)
Show icon for win/lose/draw on play landing page
Diffstat (limited to 'pkg/ui/views/play_util.go')
-rw-r--r--pkg/ui/views/play_util.go31
1 files changed, 30 insertions, 1 deletions
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)