AT Protocol Terminal Interface Explorer
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

pass query as cli arg

+74 -5
+5 -1
main.go
··· 27 27 log.SetOutput(f) 28 28 log.Warn("starting goatie") 29 29 30 - app := ui.NewApp() 30 + query := "" 31 + if len(os.Args) > 1 { 32 + query = os.Args[1] 33 + } 31 34 35 + app := ui.NewApp(query) 32 36 p := tea.NewProgram(app, tea.WithAltScreen()) 33 37 if _, err := p.Run(); err != nil { 34 38 log.Fatal(err)
+69 -4
ui/app.go
··· 25 25 active tea.Model 26 26 err string 27 27 w, h int 28 + query string 29 + spinner spinner.Model 30 + loading bool 28 31 } 29 32 30 - func NewApp() *App { 33 + func NewApp(query string) *App { 31 34 search := &CommandPallete{} 32 35 repoView := NewRepoView() 36 + spin := spinner.New() 37 + spin.Spinner = spinner.Dot 33 38 return &App{ 39 + query: query, 34 40 client: at.NewClient(""), 35 41 search: search, 36 42 repoView: repoView, 37 43 rlist: NewRecordsList(nil), 38 44 recordView: NewRecordView(false), 39 45 active: search, 46 + spinner: spin, 47 + loading: false, 40 48 } 41 49 } 42 50 43 51 func (a *App) Init() tea.Cmd { 52 + a.loading = true 53 + if id, err := syntax.ParseAtIdentifier(a.query); err == nil { 54 + log.Printf("Starting with query: %s", id.String()) 55 + return a.fetchRepo(id.String()) 56 + } 57 + if uri, err := syntax.ParseATURI(a.query); err == nil { 58 + 59 + if uri.Collection() == "" { 60 + return a.fetchRepo(uri.Authority().String()) 61 + } 62 + if uri.RecordKey().String() == "" { 63 + id := uri.Authority().Handle().String() 64 + if uri.Authority().IsDID() { 65 + id = uri.Authority().DID().String() 66 + } 67 + return a.fetchRecords(uri.Collection().String(), id) 68 + } 69 + 70 + log.Printf("Starting with query: %s", uri.String()) 71 + return a.fetchRecord(uri.Collection().String(), uri.Authority().String(), uri.RecordKey().String()) 72 + } 73 + 74 + a.loading = false 44 75 return a.active.Init() 45 76 } 46 77 ··· 92 123 } 93 124 94 125 case repoLoadedMsg: 126 + a.loading = false 95 127 cmd := a.repoView.SetRepo(msg.repo) 96 128 a.repoView.SetSize(a.w, a.h) // Set size before switching view 97 129 a.active = a.repoView ··· 103 135 return a, a.fetchRecords(msg.collection, a.repoView.repo.Handle) 104 136 105 137 case recordsLoadedMsg: 138 + a.loading = false 106 139 cmd := a.rlist.SetRecords(msg.records) 107 140 a.rlist.SetSize(a.w, a.h) // Set size before switching view 108 141 a.active = a.rlist ··· 110 143 return a, cmd 111 144 112 145 case recordSelectedMsg: 146 + a.loading = false 113 147 a.recordView.SetRecord(msg.record) 114 148 a.recordView.SetSize(a.w, a.h) // Set size before switching view 115 149 a.active = a.recordView ··· 121 155 return a, nil 122 156 } 123 157 124 - var cmd tea.Cmd 125 - a.active, cmd = a.active.Update(msg) 126 - return a, cmd 158 + 159 + var cmds []tea.Cmd 160 + if a.loading { 161 + sp, scmd := a.spinner.Update(msg) 162 + a.spinner = sp 163 + cmds = append(cmds, scmd) 164 + } 165 + var ac tea.Cmd 166 + a.active, ac = a.active.Update(msg) 167 + cmds = append(cmds, ac) 168 + return a, tea.Batch(cmds...) 127 169 } 128 170 129 171 func (a *App) fetchRepo(repoId string) tea.Cmd { ··· 156 198 } 157 199 } 158 200 201 + func (a *App) fetchRecord(collection, repo, rkey string) tea.Cmd { 202 + return func() tea.Msg { 203 + rec, err := a.client.GetRecord(context.Background(), collection, repo, rkey) 204 + if err != nil { 205 + log.Printf("Failed to get record: %s", err.Error()) 206 + return repoErrorMsg{err: err} 207 + } 208 + log.WithFields(log.Fields{ 209 + "repo": repo, 210 + "collection": collection, 211 + "rkey": rkey, 212 + }).Info("Record loaded") 213 + return recordSelectedMsg{ 214 + record: &agnostic.RepoListRecords_Record{ 215 + Uri: rec.Uri, 216 + Value: rec.Value, 217 + }} 218 + } 219 + } 220 + 159 221 func (a *App) View() string { 222 + if a.loading { 223 + return "Loading... " + a.spinner.View() 224 + } 160 225 return a.active.View() 161 226 } 162 227