Make group navigation controller-driven

This commit is contained in:
Joe Julian
2026-03-29 11:21:38 -07:00
parent 484448b51c
commit 43fc278fd1
6 changed files with 191 additions and 60 deletions
+11 -17
View File
@@ -124,7 +124,6 @@ type ui struct {
state appstate.State
masterKeyMode vault.MasterKeyMode
visible []entry
currentPath []string
selectedHistoryIndex int
showPassword bool
togglePassword widget.Clickable
@@ -224,7 +223,6 @@ func newUIWithState(mode string, sess appstate.CurrentSession) *ui {
func (u *ui) filter() {
u.state.SearchQuery = u.search.Text()
u.state.CurrentPath = append([]string(nil), u.currentPath...)
visible, err := u.state.VisibleEntries()
if err != nil {
u.visible = nil
@@ -238,25 +236,24 @@ func (u *ui) filter() {
func (u *ui) showEntriesSection() {
u.state.Section = appstate.SectionEntries
u.currentPath = nil
u.state.NavigateToPath(nil)
u.filter()
}
func (u *ui) showTemplatesSection() {
u.state.Section = appstate.SectionTemplates
u.currentPath = nil
u.state.NavigateToPath(nil)
u.filter()
}
func (u *ui) showRecycleBinSection() {
u.state.Section = appstate.SectionRecycleBin
u.currentPath = nil
u.state.NavigateToPath(nil)
u.filter()
}
func (u *ui) childGroups() []string {
u.state.SearchQuery = u.search.Text()
u.state.CurrentPath = append([]string(nil), u.currentPath...)
groups, err := u.state.ChildGroups()
if err != nil {
return nil
@@ -364,7 +361,6 @@ func (u *ui) createVaultAction() error {
if err := u.state.CreateVault(key); err != nil {
return err
}
u.currentPath = nil
u.filter()
return nil
}
@@ -377,7 +373,6 @@ func (u *ui) openVaultAction() error {
if err := u.state.OpenVault(strings.TrimSpace(u.vaultPath.Text()), key); err != nil {
return err
}
u.currentPath = nil
u.filter()
return nil
}
@@ -411,7 +406,6 @@ func (u *ui) openRemoteAction() error {
if err := u.state.OpenRemoteVault(client, strings.TrimSpace(u.remotePath.Text()), key); err != nil {
return err
}
u.currentPath = nil
u.filter()
return nil
}
@@ -553,8 +547,8 @@ func (u *ui) detailPlaceholderMessage() string {
}
func (u *ui) ensureNavClickables() {
if len(u.breadcrumbs) < len(u.currentPath)+1 {
u.breadcrumbs = make([]widget.Clickable, len(u.currentPath)+1)
if len(u.breadcrumbs) < len(u.state.CurrentPath)+1 {
u.breadcrumbs = make([]widget.Clickable, len(u.state.CurrentPath)+1)
}
}
@@ -605,7 +599,7 @@ func (u *ui) layout(gtx layout.Context) layout.Dimensions {
for u.addEntry.Clicked(gtx) {
u.state.SelectedEntryID = ""
u.loadSelectedEntryIntoEditor()
u.entryPath.SetText(strings.Join(u.currentPath, " / "))
u.entryPath.SetText(strings.Join(u.state.CurrentPath, " / "))
u.statusMessage = "new entry form ready"
u.errorMessage = ""
}
@@ -1229,9 +1223,9 @@ func (u *ui) pathBar(gtx layout.Context) layout.Dimensions {
return lbl.Layout(gtx)
}
crumbs := append([]string{"Vault"}, append([]string{}, u.currentPath...)...)
crumbs := append([]string{"Vault"}, append([]string{}, u.state.CurrentPath...)...)
if u.state.Section == appstate.SectionTemplates {
crumbs = append([]string{"Templates"}, append([]string{}, u.currentPath...)...)
crumbs = append([]string{"Templates"}, append([]string{}, u.state.CurrentPath...)...)
}
return layout.Flex{Alignment: layout.Middle}.Layout(gtx, func() []layout.FlexChild {
children := make([]layout.FlexChild, 0, len(crumbs)*2)
@@ -1241,9 +1235,9 @@ func (u *ui) pathBar(gtx layout.Context) layout.Dimensions {
children = append(children, layout.Rigid(func(gtx layout.Context) layout.Dimensions {
for u.breadcrumbs[index].Clicked(gtx) {
if index == 0 {
u.currentPath = nil
u.state.NavigateToPath(nil)
} else {
u.currentPath = append([]string{}, crumbs[1:index+1]...)
u.state.NavigateToPath(crumbs[1 : index+1])
}
u.filter()
}
@@ -1280,7 +1274,7 @@ func (u *ui) groupBar(gtx layout.Context) layout.Dimensions {
name := group
children = append(children, layout.Rigid(func(gtx layout.Context) layout.Dimensions {
for u.groupClicks[idx].Clicked(gtx) {
u.currentPath = append(append([]string{}, u.currentPath...), name)
u.state.EnterGroup(name)
u.filter()
}
btn := material.Button(u.theme, &u.groupClicks[idx], "Folder: "+name)