Skip to content

Commit

Permalink
feat: embed hint view (#58)
Browse files Browse the repository at this point in the history
* feat: fill active issue hint

* feat: auto select hint value in deck on reveal
  • Loading branch information
igor-sirotin authored Jun 30, 2024
1 parent c30d3a0 commit 88a5154
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
22 changes: 14 additions & 8 deletions internal/view/components/deckview/deckview.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"

"github.com/six78/2-story-points-cli/internal/config"
"github.com/six78/2-story-points-cli/internal/view/components/cursor"
"github.com/six78/2-story-points-cli/internal/view/components/voteview"
Expand All @@ -18,14 +19,15 @@ var (
)

type Model struct {
deck protocol.Deck
voteState protocol.VoteState
myVote protocol.VoteValue
focused bool
isDealer bool
commandMode bool
voteCursor cursor.Model
finishCursor cursor.Model
deck protocol.Deck
voteState protocol.VoteState
myVote protocol.VoteValue
votesRevealed bool
focused bool
isDealer bool
commandMode bool
voteCursor cursor.Model
finishCursor cursor.Model
}

func New() Model {
Expand All @@ -49,8 +51,12 @@ func (m Model) Update(msg tea.Msg) Model {
m.deck = protocol.Deck{}
m.voteState = protocol.IdleState
m.voteCursor.SetRange(0, 0)
m.finishCursor.SetRange(0, 0)
} else {
m.deck = msg.State.Deck
if msg.State.VotesRevealed && !m.votesRevealed {
m.finishCursor.SetPosition(msg.State.ActiveIssueHintDeckIndex())
}
m.voteState = msg.State.VoteState()
m.voteCursor.SetRange(0, len(m.deck)-1)
m.finishCursor.SetRange(0, len(m.deck)-1)
Expand Down
32 changes: 28 additions & 4 deletions pkg/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import (
"context"
"encoding/json"
"fmt"
"reflect"
"time"

"github.com/jonboulle/clockwork"
"github.com/pkg/errors"
"go.uber.org/zap"
"golang.org/x/exp/slices"

"github.com/six78/2-story-points-cli/internal/transport"
"github.com/six78/2-story-points-cli/pkg/protocol"
"github.com/six78/2-story-points-cli/pkg/storage"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"reflect"
"time"
)

var (
Expand Down Expand Up @@ -187,6 +189,10 @@ func (g *Game) CurrentState() *protocol.State {
}

func (g *Game) notifyChangedState(publish bool) {
if g.state != nil && g.state.VotesRevealed {
g.fillActiveIssueHint()
}

state := g.hiddenCurrentState()

g.logger.Debug("notifying state change",
Expand Down Expand Up @@ -798,3 +804,21 @@ func (g *Game) loadStateFromStorage(roomID protocol.RoomID) *protocol.State {

return state
}

func (g *Game) fillActiveIssueHint() {
if g.state == nil {
return
}

item := g.state.Issues.Get(g.state.ActiveIssue)
if item == nil {
g.logger.Error("failed to fill active issue hint: vote item not found in the vote list")
return
}

var err error
item.Hint, err = GetResultHint(g.state.Deck, item.Votes)
if err != nil {
g.logger.Error("failed to generate hint", zap.Error(err))
}
}

0 comments on commit 88a5154

Please sign in to comment.