diff --git a/ui/cmd/greeting/model.go b/ui/cmd/greeting/model.go index d4814c4..5e12a2c 100644 --- a/ui/cmd/greeting/model.go +++ b/ui/cmd/greeting/model.go @@ -55,8 +55,8 @@ const ( ) type Model struct { - ctx context.Context - base *base.Model + ctx context.Context + *base.Base phase Phase questionIndex int qaList []*QA @@ -66,7 +66,7 @@ type Model struct { } func NewModel(ctx context.Context, port string) (*Model, error) { - base, err := base.NewModel() + base, err := base.New() if err != nil { return nil, err } @@ -79,7 +79,7 @@ func NewModel(ctx context.Context, port string) (*Model, error) { return &Model{ ctx: ctx, - base: base, + Base: base, phase: questionPhase, questionIndex: 0, qaList: qaListTemplate, diff --git a/ui/cmd/greeting/update.go b/ui/cmd/greeting/update.go index 82d6135..d1777a4 100644 --- a/ui/cmd/greeting/update.go +++ b/ui/cmd/greeting/update.go @@ -24,10 +24,10 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case "enter": switch m.phase { case questionPhase: - m.qaList[m.questionIndex].answer = m.base.TextInput.Value() - m.base.Conversation = append(m.base.Conversation, &base.Message{ + m.qaList[m.questionIndex].answer = m.TextInput.Value() + m.Conversation = append(m.Conversation, &base.Message{ Speaker: base.User, - Content: m.base.TextInput.Value(), + Content: m.TextInput.Value(), }) return m, tea.Batch(inputCmd, m.setConfig) case authPhase: @@ -41,7 +41,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case questionCompMsg: if msg.isDone { m.phase = authPhase - m.base.Conversation = append(m.base.Conversation, &base.Message{ + m.Conversation = append(m.Conversation, &base.Message{ Speaker: base.Bot, Content: "Please press enter to authorize", }) @@ -50,7 +50,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.user = msg.user m.spotifyClient = msg.client m.phase = devicePhase - m.base.Conversation = append(m.base.Conversation, &base.Message{ + m.Conversation = append(m.Conversation, &base.Message{ Speaker: base.Bot, Content: "Please open Spotify app to get device ID and press enter", }) @@ -60,7 +60,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.err = msg.err } - m.base.TextInput, inputCmd = m.base.TextInput.Update(msg) + m.TextInput, inputCmd = m.TextInput.Update(msg) return m, inputCmd } @@ -70,18 +70,18 @@ type questionCompMsg struct { } func (m *Model) setConfig() tea.Msg { - if err := m.base.Cfg.Set(confKeyList[m.questionIndex], m.qaList[m.questionIndex].answer); err != nil { + if err := m.Cfg.Set(confKeyList[m.questionIndex], m.qaList[m.questionIndex].answer); err != nil { return errMsg{err} } m.questionIndex++ - m.base.TextInput.Reset() + m.TextInput.Reset() if m.questionIndex == len(m.qaList) { return questionCompMsg{ isDone: true, } } - m.base.Conversation = append(m.base.Conversation, &base.Message{ + m.Conversation = append(m.Conversation, &base.Message{ Speaker: base.Bot, Content: m.qaList[m.questionIndex].question, }) @@ -96,7 +96,7 @@ type spotifyMsg struct { } func (m *Model) authorize() tea.Msg { - authClient := auth.NewClient(m.base.Cfg) + authClient := auth.NewClient(m.Cfg) authClient.Authorize() @@ -127,7 +127,7 @@ func (m *Model) getDevice() tea.Msg { } deviceID := devices[0].ID.String() - if err := m.base.Cfg.Set(config.DeviceID, deviceID); err != nil { + if err := m.Cfg.Set(config.DeviceID, deviceID); err != nil { return errMsg{err} } diff --git a/ui/cmd/greeting/view.go b/ui/cmd/greeting/view.go index 7d98e6a..07d8c9b 100644 --- a/ui/cmd/greeting/view.go +++ b/ui/cmd/greeting/view.go @@ -10,9 +10,9 @@ import ( func (m *Model) View() string { if m.err != nil { - return style.ErrorView(m.base.Window.Width, m.base.Window.Height) + return style.ErrorView(m.Window.Width, m.Window.Height) } - return lipgloss.Place(m.base.Window.Width, m.base.Window.Height, lipgloss.Center, lipgloss.Center, + return lipgloss.Place(m.Window.Width, m.Window.Height, lipgloss.Center, lipgloss.Center, lipgloss.JoinVertical( lipgloss.Center, style.AsciiArt().Render(asciiArtView), @@ -22,12 +22,12 @@ func (m *Model) View() string { } func (m *Model) getViewWidth() int { - halfWidth := m.base.Window.Width / 2 + halfWidth := m.Window.Width / 2 return halfWidth } func (m *Model) getViewHeight() int { - halfHeight := m.base.Window.Height * 2 / 3 + halfHeight := m.Window.Height * 2 / 3 return halfHeight } @@ -50,7 +50,7 @@ func (m *Model) chatView() string { s = lipgloss.Place(m.getViewWidth(), m.getViewHeight(), lipgloss.Center, lipgloss.Center, ss) default: var lastSpeaker base.Speaker - for _, message := range m.base.Conversation { + for _, message := range m.Conversation { if message.Speaker == base.Bot { s += style.BotChat(m.getViewWidth()).Render(message.Content) + "\n\n" lastSpeaker = base.Bot @@ -60,7 +60,7 @@ func (m *Model) chatView() string { } } if s != "" && lastSpeaker == base.Bot && m.phase == questionPhase { - s += style.TextInput().Render(m.base.TextInput.View()) + s += style.TextInput().Render(m.TextInput.View()) } } return s