Skip to content

Commit fcdcf11

Browse files
committed
feat(ui): update error detection rendering position
update error detection rendering position Signed-off-by: mritd <[email protected]>
1 parent 96754a3 commit fcdcf11

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

ui_commit.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package main
33
import (
44
"strings"
55

6+
"github.com/charmbracelet/bubbles/spinner"
7+
68
tea "github.com/charmbracelet/bubbletea"
79
)
810

@@ -58,9 +60,9 @@ func (m *commitModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5860
// some special views need to determine the state of the data to update
5961
switch m.viewIndex {
6062
case INPUTS:
61-
return m, m.inputs
63+
return m, tea.Batch(spinner.Tick, m.inputs)
6264
case COMMIT:
63-
return m, m.commit
65+
return m, tea.Batch(spinner.Tick, m.commit)
6466
case ERROR:
6567
return m, m.showErr
6668
default:

ui_commit_committing.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,11 @@ func (m committingModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9494
return m, nil
9595
}
9696
case commitMsg:
97-
var cmd tea.Cmd
98-
m.spinner, cmd = m.spinner.Update(spinner.Tick())
9997
m.msg = msg
100-
return m, tea.Batch(cmd, func() tea.Msg {
98+
return m, func() tea.Msg {
10199
time.Sleep(time.Second)
102100
return commit(msg)
103-
})
101+
}
104102
case error:
105103
m.done = true
106104
m.err = msg

ui_commit_inputs.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type inputsModel struct {
8888
}
8989

9090
func (m inputsModel) Init() tea.Cmd {
91-
return textinput.Blink
91+
return tea.Batch(textinput.Blink, spinner.Tick)
9292
}
9393

9494
func (m inputsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@@ -145,13 +145,6 @@ func (m inputsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
145145
m.inputs[i].input.TextStyle = inputsTextNormalStyle
146146
}
147147

148-
if m.focusIndex < len(m.inputs) && m.inputs[m.focusIndex].checker != nil {
149-
m.err = m.inputs[m.focusIndex].checker(m.inputs[m.focusIndex].input.Value())
150-
cmds = append(cmds, spinner.Tick)
151-
} else {
152-
m.err = nil
153-
}
154-
155148
return m, tea.Batch(cmds...)
156149
}
157150
case string:
@@ -196,12 +189,19 @@ func (m inputsModel) View() string {
196189
button = inputsButtonStyle.Render("➜ Submit")
197190
}
198191

199-
if m.err != nil {
200-
b.WriteString(inputsButtonBlockStyle.Render(button + inputsErrLayout.Render(m.errSpinner.View()+" "+inputsErrStyle.Render(m.err.Error()))))
201-
} else {
202-
b.WriteString(inputsButtonBlockStyle.Render(button))
192+
// check input value
193+
for _, iwc := range m.inputs {
194+
if iwc.checker != nil {
195+
m.err = iwc.checker(iwc.input.Value())
196+
if m.err != nil {
197+
button += inputsErrLayout.Render(m.errSpinner.View() + " " + inputsErrStyle.Render(m.err.Error()))
198+
break
199+
}
200+
}
203201
}
204202

203+
b.WriteString(inputsButtonBlockStyle.Render(button))
204+
205205
title := inputsTitleBarStyle.Render(inputsTitleStyle.Render(m.title))
206206
inputs := inputsBlockStyle.Render(b.String())
207207

0 commit comments

Comments
 (0)