fix: the details pane follows its secret's list when it reloads
A cached list is shown at once and reloaded in the background; the selected secret's details stayed as first shown, old web page included, until another secret was selected. When the reloaded list has it changed, the details pane takes the new listing (a value shown stays shown) and describes it afresh: its cached details came from the old one. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
4 files changed
+75
No files matched your search
@@ -1,8 +1,12 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
|
||||
"git.kebcloud.no/keb/lazysecrets/internal/provider"
|
||||
)
|
||||
|
||||
@@ -48,3 +52,31 @@ func (c cache) rememberCursor(parent, child string) {
|
||||
c.cursor[parent] = child
|
||||
}
|
||||
}
|
||||
|
||||
// refreshShown shows the selected secret's newer metadata when its list
|
||||
// reloaded with it changed from before (a cached list refreshed in the
|
||||
// background), and describes it afresh: its cached details came from
|
||||
// the old listing.
|
||||
func (m *Model) refreshShown(before []provider.Object) tea.Cmd {
|
||||
s, ok := m.secrets.Selected()
|
||||
if !ok || m.secrets.SelectedID() != m.selSecret {
|
||||
return nil // a new selection is shown as usual
|
||||
}
|
||||
i := slices.IndexFunc(before, func(o provider.Object) bool { return o.ID == s.ID })
|
||||
if i < 0 || sameListing(before[i], s) {
|
||||
return nil
|
||||
}
|
||||
m.detail.Refresh(s)
|
||||
delete(m.cache.details, detailKey(s))
|
||||
return m.describe(s)
|
||||
}
|
||||
|
||||
// sameListing reports whether a and b list the same: what a list
|
||||
// says of an object, not what describing it adds.
|
||||
func sameListing(a, b provider.Object) bool {
|
||||
enabled := func(e *bool) bool { return e == nil || *e }
|
||||
return a.Name == b.Name && a.Version == b.Version && enabled(a.Enabled) == enabled(b.Enabled) &&
|
||||
a.Updated.Equal(b.Updated) && a.Expires.Equal(b.Expires) && a.ContentType == b.ContentType &&
|
||||
maps.Equal(a.Tags, b.Tags) && a.Reference == b.Reference && a.URL == b.URL &&
|
||||
slices.Equal(a.Attrs, b.Attrs)
|
||||
}
|
||||
Reference in new issue
Block a user