support refreshing data

This commit is contained in:
talksik
2025-10-27 16:17:23 -07:00
parent 9401d5002d
commit 7fec49ff04
+20 -16
View File
@@ -102,7 +102,6 @@ type model struct {
viewport viewport.Model
detailViewport viewport.Model
ready bool
showKeypad bool
terminalWidth int
terminalHeight int
focusOnDetail bool // true = detail panel has focus, false = list has focus
@@ -110,9 +109,8 @@ type model struct {
func initialModel(humans []*HumanData) model {
return model{
humans: humans,
cursor: 0,
showKeypad: false,
humans: humans,
cursor: 0,
}
}
@@ -181,6 +179,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
case "r":
m.humans = getHumansData()
m.cursor = 0
m.viewport.SetContent(m.renderList())
m.detailViewport.SetContent(m.renderDetails())
m.detailViewport.GotoTop()
case "down", "j":
if m.cursor < len(m.humans)-1 {
m.cursor++
@@ -282,7 +287,7 @@ func (m model) View() string {
statusBar := statusStyle.Render(fmt.Sprintf(" %d/%d", m.cursor+1, len(m.humans)))
// Help text
help := helpStyle.Render("↑/k up • ↓/j down • ctrl+u/d scroll detail • q quit")
help := helpStyle.Render("↑/k up • ↓/j down • ctrl+u/d scroll detail • r refresh • q quit")
// Create two-column layout
leftPanel := m.viewport.View()
@@ -308,6 +313,15 @@ func unaryInterceptor(ctx context.Context, method string, req, reply interface{}
func main() {
logrus.Infof("hello world")
humansData := getHumansData()
p := tea.NewProgram(initialModel(humansData))
if _, err := p.Run(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}
}
func getHumansData() []*HumanData {
heliosAddr := "helios.flowy.live:443"
creds := credentials.NewTLS(&tls.Config{
InsecureSkipVerify: true,
@@ -332,12 +346,6 @@ func main() {
os.Exit(1)
}
keypadsResponse.GetHumanKeypads()[0].GetHumanId()
keypadsResponse.GetHumanKeypads()[0].GetYamlConfig()
logrus.Info("connected to helios")
logrus.Infof("fetched %d humans", len(humansResponse.GetHumans()))
humansData := []*HumanData{}
for _, human := range humansResponse.GetHumans() {
keypadConfiguration := ""
@@ -354,9 +362,5 @@ func main() {
})
}
p := tea.NewProgram(initialModel(humansData))
if _, err := p.Run(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
}
return humansData
}