Skip to content

Commit

Permalink
feat: renderCardFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Sep 1, 2024
1 parent 707f607 commit 492a666
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
24 changes: 16 additions & 8 deletions internal/view/components/deckview/deckview.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ func (m Model) View() string {
card := renderCard(
value,
m.deck,
m.voteCursor.Match(i),
m.finishCursor.Match(i),
value == m.myVote,
renderCardFlags{
voteCursor: m.voteCursor.Match(i),
finishCursor: m.finishCursor.Match(i),
voted: value == m.myVote,
},
)
cards = append(cards, card, " ") // Add a space between cards
}
Expand Down Expand Up @@ -121,10 +123,16 @@ func (m *Model) FinishCursor() int {
return m.finishCursor.Position()
}

func renderCard(value protocol.VoteValue, deck protocol.Deck, voteCursor bool, finishCursor bool, voted bool) string {
type renderCardFlags struct {
voteCursor bool
finishCursor bool
voted bool
}

func renderCard(value protocol.VoteValue, deck protocol.Deck, flags renderCardFlags) string {
card := table.New().
Border(lipgloss.RoundedBorder()).
BorderStyle(*cardBorderStyle(voted, finishCursor)).
BorderStyle(*cardBorderStyle(flags.voted, flags.finishCursor)).
StyleFunc(func(row, col int) lipgloss.Style {
return *voteview.VoteStyle(value, deck)
}).
Expand All @@ -134,14 +142,14 @@ func renderCard(value protocol.VoteValue, deck protocol.Deck, voteCursor bool, f
var column []string
column = []string{}

if !voted {
if !flags.voted {
column = append(column, "")
}

column = append(column, card)

if voteCursor {
if voted {
if flags.voteCursor {
if flags.voted {
column = append(column, "")
}
column = append(column, " ^")
Expand Down
6 changes: 5 additions & 1 deletion internal/view/components/deckview/deckview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ func (s *Suite) TestRenderCard() {
}

for _, tc := range testCases {
result := renderCard(tc.value, deck, tc.cursor, false, tc.voted)
result := renderCard(tc.value, deck, renderCardFlags{
voteCursor: tc.cursor,
finishCursor: false,
voted: tc.voted},
)
s.Require().Equal(tc.expected, result)
}
}
Expand Down

0 comments on commit 492a666

Please sign in to comment.