Centralize app state ownership in controller

This commit is contained in:
Joe Julian
2026-03-29 11:22:17 -07:00
parent 01559a3a2b
commit b56401b5c6
5 changed files with 186 additions and 40 deletions
+51
View File
@@ -75,6 +75,35 @@ type State struct {
SearchQuery string
SelectedEntryID string
Dirty bool
StatusMessage string
ErrorMessage string
}
func (s *State) ShowSection(section Section) {
s.Section = section
s.CurrentPath = nil
s.SelectedEntryID = ""
}
func (s *State) SetSearchQuery(query string) {
s.SearchQuery = query
}
func (s *State) BeginNewEntry() {
s.SelectedEntryID = ""
s.StatusMessage = "new entry form ready"
s.ErrorMessage = ""
}
func (s *State) SetActionResult(label string, err error) {
if err != nil {
s.ErrorMessage = err.Error()
s.StatusMessage = ""
return
}
s.ErrorMessage = ""
s.StatusMessage = label + " complete"
}
func (s *State) VisibleEntries() ([]vault.Entry, error) {
@@ -467,6 +496,28 @@ func (s *State) NavigateToPath(path []string) {
s.SelectedEntryID = ""
}
func (s *State) DeleteCurrentGroup() error {
session, ok := s.Session.(MutableSession)
if !ok {
return fmt.Errorf("session is not mutable")
}
model, err := session.Current()
if err != nil {
return err
}
if err := model.DeleteGroup(s.CurrentPath); err != nil {
return err
}
session.Replace(model)
if len(s.CurrentPath) > 0 {
s.CurrentPath = append([]string(nil), s.CurrentPath[:len(s.CurrentPath)-1]...)
}
s.Dirty = true
return nil
}
func (s *State) Save() error {
session, ok := s.Session.(SaveableSession)
if !ok {