Tree Browser Work
This commit is contained in:
@@ -23,8 +23,10 @@ package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.bullercodeworks.com/brian/expds/data"
|
||||
"git.bullercodeworks.com/brian/expds/data/models"
|
||||
@@ -43,8 +45,7 @@ type ScreenHome struct {
|
||||
w, h int
|
||||
style tcell.Style
|
||||
|
||||
alert *w.Alert
|
||||
showAlert bool
|
||||
alert *w.Alert
|
||||
|
||||
menuLayout *w.TopMenuLayout
|
||||
|
||||
@@ -164,9 +165,6 @@ func (s *ScreenHome) HandleResize(ev *tcell.EventResize) {
|
||||
}
|
||||
|
||||
func (s *ScreenHome) HandleKey(ev *tcell.EventKey) bool {
|
||||
if s.showAlert {
|
||||
return s.alert.HandleKey(ev)
|
||||
}
|
||||
if ev.Key() == tcell.KeyF12 {
|
||||
s.toggleCli()
|
||||
return true
|
||||
@@ -213,9 +211,6 @@ func (s *ScreenHome) Draw() {
|
||||
s.a.DrawWidget(s.loading)
|
||||
}
|
||||
s.a.DrawWidget(s.status)
|
||||
if s.showAlert {
|
||||
s.a.DrawWidget(s.alert)
|
||||
}
|
||||
}
|
||||
func (s *ScreenHome) Exit() error { return nil }
|
||||
func (s *ScreenHome) Log(t string, a ...any) {
|
||||
@@ -316,9 +311,11 @@ func (s *ScreenHome) initCli() {
|
||||
func (s *ScreenHome) toggleCli() {
|
||||
if s.layout.Contains(s.cli) {
|
||||
s.layout.Delete(s.cli)
|
||||
s.layout.ActivateWidget(s.columns)
|
||||
} else {
|
||||
s.layout.Add(s.cli)
|
||||
s.cli.SetVisible(true)
|
||||
s.layout.ActivateWidget(s.cli)
|
||||
}
|
||||
}
|
||||
func (s *ScreenHome) hideCli() {
|
||||
@@ -344,7 +341,13 @@ func (s *ScreenHome) cliGetPds(args ...string) bool {
|
||||
}
|
||||
go func() {
|
||||
defer func() { s.isLoading = false }()
|
||||
pds, err := s.r.GetPDS(args[1])
|
||||
var pds *models.Pds
|
||||
var err error
|
||||
if s.activePds != nil && string(s.activePds.AtId) == args[1] {
|
||||
pds, err = s.r.ReloadPds(args[1])
|
||||
} else {
|
||||
pds, err = s.r.GetPDS(args[1])
|
||||
}
|
||||
if err != nil {
|
||||
s.Log(err.Error())
|
||||
return
|
||||
@@ -353,7 +356,7 @@ func (s *ScreenHome) cliGetPds(args ...string) bool {
|
||||
return
|
||||
}
|
||||
s.doOpen = false
|
||||
s.cli.Log("Retrieved: %s (%s)", pds.AtId, pds.Did)
|
||||
slog.Default().Debug(fmt.Sprintf("Retrieved: %s (%s) at %s", pds.AtId, pds.Did, time.Now().Format(time.RFC3339)))
|
||||
s.activePds = pds
|
||||
s.updatePdsListing()
|
||||
n, err := s.pdsListing.GetActiveNode()
|
||||
@@ -388,9 +391,8 @@ func (s *ScreenHome) cliAuthPds(args ...string) bool {
|
||||
if err != nil {
|
||||
s.Log("Error starting auth flow: %w", err)
|
||||
}
|
||||
s.alert.SetTitle("Authentication Started")
|
||||
s.alert.SetMessage(fmt.Sprintf("OAuth Process Started.\nIf a browser window didn't open, you can open this URL manually:\n%s", authUrl))
|
||||
s.showAlert = true
|
||||
s.Log("Authentication Started")
|
||||
s.Log(fmt.Sprintf("OAuth Process Started.\nIf a browser window didn't open, you can open this URL manually:\n%s", strings.ReplaceAll(authUrl, "%", "%%")))
|
||||
}()
|
||||
return true
|
||||
}
|
||||
@@ -421,11 +423,14 @@ func (s *ScreenHome) cliSendStatus(args ...string) bool {
|
||||
s.isLoading = true
|
||||
go func() {
|
||||
defer func() { s.isLoading = false }()
|
||||
if !s.r.Auth.HasAuth() {
|
||||
if !s.r.Auth.HasAuth(s.activePds.Did) {
|
||||
s.Log("Not authorized. Run `authpds`")
|
||||
return
|
||||
}
|
||||
s.r.SendToPDS()
|
||||
err := s.r.SendToPDS(s.activePds.Did)
|
||||
if err != nil {
|
||||
s.Log("Error sending status: %w", err)
|
||||
}
|
||||
}()
|
||||
return true
|
||||
}
|
||||
@@ -434,6 +439,7 @@ func (s *ScreenHome) updatePdsListing() {
|
||||
s.pdsListing.SetTitle(fmt.Sprintf("─ %s (%s)", s.activePds.AtId.String(), s.activePds.Did.String()))
|
||||
s.pdsListing.Clear()
|
||||
nsidList := s.activePds.NSIDStringList()
|
||||
var tree []*wd.TreeNode
|
||||
for i, v := range nsidList {
|
||||
t := wd.NewTreeNode(v, v)
|
||||
nsid := s.activePds.NSIDs[i]
|
||||
@@ -456,8 +462,9 @@ func (s *ScreenHome) updatePdsListing() {
|
||||
c := wd.NewTreeNode(label, rIds[j])
|
||||
t.AddChild(c)
|
||||
}
|
||||
s.pdsListing.Add(t)
|
||||
tree = append(tree, t)
|
||||
}
|
||||
s.pdsListing.SetTree(tree)
|
||||
s.layout.ActivateWidget(s.columns)
|
||||
s.columns.ActivateWidget(s.pdsListing)
|
||||
s.pdsListing.SetActive(true)
|
||||
|
||||
Reference in New Issue
Block a user