Add the ability to start the tracker when submitting an entry
All checks were successful
CI / test (push) Successful in 1m1s

This commit is contained in:
Justin Hawkins 2025-06-20 17:08:39 +02:00
parent 6116e89aac
commit c7798c5784

View File

@ -35,6 +35,7 @@ func (m model) updateForm(msg tea.Msg) (tea.Model, tea.Cmd) {
projectID := m.formData.form.GetString("project") projectID := m.formData.form.GetString("project")
description := m.formData.form.GetString("description") description := m.formData.form.GetString("description")
minutes := m.formData.form.GetString("minutes") minutes := m.formData.form.GetString("minutes")
tracker := m.formData.form.GetBool("tracker")
minutesInt, err1 := strconv.ParseInt(minutes, 10, 64) minutesInt, err1 := strconv.ParseInt(minutes, 10, 64)
serviceIDInt, err2 := strconv.ParseInt(serviceID, 10, 64) serviceIDInt, err2 := strconv.ParseInt(serviceID, 10, 64)
@ -45,14 +46,27 @@ func (m model) updateForm(msg tea.Msg) (tea.Model, tea.Cmd) {
m.tuiMode = MODE_CAL m.tuiMode = MODE_CAL
} else { } else {
err := m.miteAPI.AddTimeEntry(m.dest.Format(time.DateOnly), int(minutesInt), description, int(projectIDInt), int(serviceIDInt)) id, err := m.miteAPI.AddTimeEntry(m.dest.Format(time.DateOnly), int(minutesInt), description, int(projectIDInt), int(serviceIDInt))
if err != nil { if err != nil {
m.statusBarMessage = err.Error() m.statusBarMessage = err.Error()
m.tuiMode = MODE_CAL m.tuiMode = MODE_CAL
} else { } else {
m.statusBarMessage = "Successfully logged time" if tracker {
m.tuiMode = MODE_CAL _, _, err = m.miteAPI.StartTimeTracker(id)
return m, m.fetchMiteData() if err != nil {
m.statusBarMessage = err.Error()
m.tuiMode = MODE_CAL
} else {
m.statusBarMessage = "Successfully logged time and started tracker"
m.tuiMode = MODE_CAL
return m, m.fetchMiteData()
}
} else {
m.statusBarMessage = "Successfully logged time"
m.tuiMode = MODE_CAL
return m, m.fetchMiteData()
}
} }
} }
@ -101,38 +115,51 @@ func (m model) buildForm() *huh.Form {
Key("project"). Key("project").
Title("Project"). Title("Project").
Options(projOptions...). Options(projOptions...).
Height(10) Height(6)
description := huh.NewText().
Key("description").
Title("description").
Validate(func(s string) error {
if s == "" {
return errors.New("must enter a description")
}
return nil
})
defMinutes := "0"
minutes := huh.NewInput().
Key("minutes").
CharLimit(5).
Validate(
func(s string) error {
h, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
}
if h < 0 {
return errors.New("must be positive")
}
return err
}).
Title("Minutes").
Value(&defMinutes)
confirmTracker := huh.NewConfirm().
Key("tracker").
Affirmative("Yes").
Negative("No").
Title("Start tracker")
form := huh.NewForm( form := huh.NewForm(
huh.NewGroup( huh.NewGroup(
pl, pl,
sl, sl,
description,
), ),
huh.NewGroup( huh.NewGroup(
huh.NewText(). minutes,
Key("description"). confirmTracker,
Title("description").
Validate(func(s string) error {
if s == "" {
return errors.New("must enter a description")
}
return nil
}),
huh.NewInput().
Key("minutes").
CharLimit(5).
Validate(
func(s string) error {
h, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
}
if h < 0 {
return errors.New("must be positive")
}
return err
}).
Title("Minutes"),
), ),
) )
return form return form