diff --git a/internal/config/config.go b/internal/config/config.go index 1dd585e..1c999d2 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -486,28 +486,17 @@ func (c *Config) GetStateColor(stateName string) string { return "99" } -// AddState adds a new state to the configuration -func (c *Config) AddState(name, color string) { - // Check if state already exists - for i, state := range c.States.States { - if state.Name == name { - c.States.States[i].Color = color - return - } - } - c.States.States = append(c.States.States, StateConfig{Name: name, Color: color}) -} - -// AddDoneState adds (or upgrades) a state and marks it as a done state. -func (c *Config) AddDoneState(name, color string) { +// AddState adds (or upgrades) a state in the configuration, marking it as a +// done state when done is true. +func (c *Config) AddState(name, color string, done bool) { for i := range c.States.States { if c.States.States[i].Name == name { c.States.States[i].Color = color - c.States.States[i].Done = true + c.States.States[i].Done = done return } } - c.States.States = append(c.States.States, StateConfig{Name: name, Color: color, Done: true}) + c.States.States = append(c.States.States, StateConfig{Name: name, Color: color, Done: done}) } // RemoveState removes a state from the configuration diff --git a/internal/config/config_test.go b/internal/config/config_test.go index d762436..6cb3111 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -52,7 +52,7 @@ func TestFillDefaultsLeavesExplicitDoneFlagsAlone(t *testing.T) { func TestAddDoneState(t *testing.T) { c := &Config{} - c.AddDoneState("CANCELLED", "240") + c.AddState("CANCELLED", "240", true) if len(c.States.States) != 1 { t.Fatalf("expected 1 state, got %d", len(c.States.States)) @@ -63,8 +63,8 @@ func TestAddDoneState(t *testing.T) { } // Adding an existing name upgrades it to done. - c.AddState("REVIEW", "99") - c.AddDoneState("REVIEW", "99") + c.AddState("REVIEW", "99", false) + c.AddState("REVIEW", "99", true) for _, st := range c.States.States { if st.Name == "REVIEW" && !st.Done { t.Fatal("expected REVIEW upgraded to done") diff --git a/internal/ui/stateform.go b/internal/ui/stateform.go index 0938c78..7835b6e 100644 --- a/internal/ui/stateform.go +++ b/internal/ui/stateform.go @@ -108,11 +108,7 @@ func (m *uiModel) applyStateForm() bool { if color == "" { color = "99" } - if sf.done { - m.config.AddDoneState(name, color) - } else { - m.config.AddState(name, color) - } + m.config.AddState(name, color, sf.done) m.setStatus(fmt.Sprintf("Added state '%s' (saved)", name)) return true }