1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-06-09 06:20:43 +00:00

Disabled test, added Aggregator to UI

This commit is contained in:
マリウス 2022-12-30 03:30:03 -05:00
parent 7e94fcd909
commit 7f140a4243
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
2 changed files with 21 additions and 19 deletions

View File

@ -1,11 +1,7 @@
package cmd
import (
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
"github.com/mrusme/gobbs/aggregator"
"github.com/mrusme/gobbs/config"
"github.com/mrusme/gobbs/system"
"github.com/mrusme/gobbs/ui"
@ -77,21 +73,23 @@ var rootCmd = &cobra.Command{
"in Go, supporting Discourse and Lemmy.\n" +
"More info available on https://xn--gckvb8fzb.com/projects/gobbs",
Run: func(cmd *cobra.Command, args []string) {
var err error
c := ctx.New(&CFG, LOG)
_ = loadSystems(&c) // TODO: Handle errs
a, _ := aggregator.New(&c)
posts, errs := a.ListPosts()
// posts, err := (*c.Systems[0]).ListPosts()
fmt.Println("-----------------------")
fmt.Printf("%v\n", posts)
fmt.Printf("%v\n", errs)
// err = s(*c.Systems[0]).LoadPost(&posts[4])
err := a.LoadPost(&posts[4])
fmt.Printf("%v\n", posts[4].Replies[2])
fmt.Printf("%v\n", err)
os.Exit(0)
// a, _ := aggregator.New(&c)
// posts, errs := a.ListPosts()
// // posts, err := (*c.Systems[0]).ListPosts()
// fmt.Println("-----------------------")
// fmt.Printf("%v\n", posts)
// fmt.Printf("%v\n", errs)
//
// // err = s(*c.Systems[0]).LoadPost(&posts[4])
// err := a.LoadPost(&posts[4])
// fmt.Printf("%v\n", posts[4].Replies[2])
// fmt.Printf("%v\n", err)
// os.Exit(0)
tui := tea.NewProgram(ui.NewModel(&c), tea.WithAltScreen())
err = tui.Start()

View File

@ -63,6 +63,7 @@ type Model struct {
items []list.Item
viewport viewport.Model
ctx *ctx.Ctx
a *aggregator.Aggregator
focused int
focusables [2]tea.Model
@ -84,6 +85,7 @@ func NewModel(c *ctx.Ctx) Model {
m.list = list.New(m.items, list.NewDefaultDelegate(), 0, 0)
m.list.Title = "Posts"
m.ctx = c
m.a, _ = aggregator.New(m.ctx)
return m
}
@ -172,8 +174,7 @@ func (m *Model) refresh() tea.Cmd {
return func() tea.Msg {
var items []list.Item
a, _ := aggregator.New(m.ctx)
posts, errs := a.ListPosts()
posts, errs := m.a.ListPosts()
if len(errs) > 0 {
fmt.Printf("%s", errs) // TODO: Implement error message
}
@ -188,9 +189,12 @@ func (m *Model) refresh() tea.Cmd {
func (m *Model) renderViewport(post *post.Post) string {
var vp string = ""
m.a.LoadPost(post)
vp = fmt.Sprintf(
"%s\n",
"%s\n\n%s",
post.Subject,
post.Body,
)
return vp