1
0
Fork 0

Implemented first usable draft for #10

This commit is contained in:
マリウス 2023-01-10 14:36:07 -05:00
parent 51cb1d971b
commit eff17590c5
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
7 changed files with 36 additions and 3 deletions

View File

@ -259,21 +259,24 @@ func (sys *System) LoadPost(p *post.Post) error {
// first 20 posts otherwise.
p.TotalReplies = len(item.PostStream.Stream)
if p.TotalReplies > 20 {
var postIDs []int
if p.CurrentRepliesStartIDX == -1 ||
// Explain to me standard GoFmt logic:
p.CurrentRepliesStartIDX > (p.TotalReplies-20) {
p.CurrentRepliesStartIDX = (p.TotalReplies - 20)
// /)_-)
} else if p.CurrentRepliesStartIDX < -1 {
p.CurrentRepliesStartIDX = 0
}
var postIDs []int
if p.CurrentRepliesStartIDX > 0 {
postIDs = append(postIDs,
item.PostStream.Stream[0])
p.CurrentRepliesStartIDX++
}
postIDs = append(postIDs,
item.PostStream.Stream[p.CurrentRepliesStartIDX:]...)
item.PostStream.Stream[p.CurrentRepliesStartIDX:(p.CurrentRepliesStartIDX+20)]...)
replies, err := sys.client.Topics.ShowPosts(
context.Background(),

View File

@ -223,7 +223,10 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
SysIDX: sys.ID,
},
Replies: replies,
// TODO: Implement chunks loading
TotalReplies: 0,
CurrentRepliesStartIDX: -1,
Replies: replies,
URL: fmt.Sprintf("https://news.ycombinator.com/item?id=%d", i.ID),

View File

@ -202,6 +202,10 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
SysIDX: sys.ID,
},
// TODO: Implement chunks loading
TotalReplies: 0,
CurrentRepliesStartIDX: -1,
URL: fmt.Sprintf("%s/post/%d", baseURL, i.Post.ID),
SysIDX: sys.ID,

View File

@ -182,6 +182,10 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
SysIDX: sys.ID,
},
// TODO: Implement chunks loading
TotalReplies: 0,
CurrentRepliesStartIDX: -1,
URL: i.ShortIDURL,
SysIDX: sys.ID,

View File

@ -109,6 +109,16 @@ func handleOpen(mi interface{}) (bool, []tea.Cmd) {
return true, cmds
}
func handleOlder(mi interface{}) (bool, []tea.Cmd) {
var m *Model = mi.(*Model)
var cmds []tea.Cmd
m.activePost.CurrentRepliesStartIDX -= 20
m.ctx.Loading = true
cmds = append(cmds, m.loadPost(m.activePost))
return true, cmds
}
func handleNumberKeys(mi interface{}, n int8) (bool, []tea.Cmd) {
var m *Model = mi.(*Model)
var cmds []tea.Cmd

View File

@ -63,6 +63,7 @@ func NewModel(c *ctx.Ctx) Model {
m.tk.KeymapAdd("reply", "reply (prefix with #, e.g. '2r')", "r")
m.tk.KeymapAdd("open", "open", "o")
m.tk.KeymapAdd("older", "older replies", "z")
m.a, _ = aggregator.New(m.ctx)
@ -77,6 +78,10 @@ func NewModel(c *ctx.Ctx) Model {
ID: "open",
Handler: handleOpen,
},
{
ID: "older",
Handler: handleOlder,
},
},
OnAnyNumberKey: handleNumberKeys,
OnAnyUncaughtKey: handleUncaughtKeys,

View File

@ -71,6 +71,10 @@ func (m *Model) renderViewport(p *post.Post) string {
caps := (*m.ctx.Systems[p.SysIDX]).GetCapabilities()
if caps.IsCapableOf("list:replies") {
if m.activePost.CurrentRepliesStartIDX > 0 {
tmp, _ := m.glam.Render(fmt.Sprintf("\n---\nOlder replies available, press `z` to load\n\n---\n"))
out += tmp
}
out += m.renderReplies(0, p.Author.Name, &p.Replies)
}