1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-11-03 04:27:16 -05:00

Implemented refresh on reply, fixed duplicates

This commit is contained in:
マリウス 2023-01-05 23:11:55 -05:00
parent af5bfeeb06
commit 5d89d50870
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
7 changed files with 34 additions and 2 deletions

View File

@ -249,6 +249,7 @@ func (sys *System) LoadPost(p *post.Post) error {
converter := md.NewConverter("", true, nil)
p.Replies = []reply.Reply{}
for idx, i := range item.PostStream.Posts {
cookedMd, err := converter.ConvertString(i.Cooked)
if err != nil {

View File

@ -230,6 +230,7 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
}
func (sys *System) LoadPost(p *post.Post) error {
p.Replies = []reply.Reply{}
return sys.loadReplies(&p.Replies)
}

View File

@ -224,6 +224,7 @@ func (sys *System) LoadPost(p *post.Post) error {
return err
}
p.Replies = []reply.Reply{}
for _, i := range resp.Comments {
createdAt := i.Comment.Published.Time

View File

@ -194,6 +194,7 @@ func (sys *System) LoadPost(p *post.Post) error {
converter := md.NewConverter("", true, nil)
p.Replies = []reply.Reply{}
for idx, i := range item.Comments {
cookedMd, err := converter.ConvertString(i.Comment)
if err != nil {

View File

@ -2,6 +2,7 @@ package postcreate
import (
"net/url"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/mrusme/gobbs/models/post"
@ -103,6 +104,9 @@ func handleSubmit(mi interface{}) (bool, []tea.Cmd) {
m.textarea.Reset()
m.replyToIdx = 0
cmds = append(cmds, cmd.New(cmd.WMCloseWin, WIN_ID).Tea())
cmds = append(cmds, cmd.New(cmd.WinRefreshData, "*", cmd.Arg{
Name: "delay", Value: (3 * time.Second),
}).Tea())
return true, cmds
}

View File

@ -3,6 +3,7 @@ package postshow
import (
"errors"
"strconv"
"time"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
@ -159,6 +160,23 @@ func handleWinOpenCmd(mi interface{}, c cmd.Command) (bool, []tea.Cmd) {
return false, cmds
}
func handleWinRefreshDataCmd(mi interface{}, c cmd.Command) (bool, []tea.Cmd) {
var m *Model = mi.(*Model)
var cmds []tea.Cmd
if c.Target == WIN_ID ||
c.Target == "*" {
m.ctx.Loading = true
if delay := c.GetArg("delay"); delay != nil {
cmds = append(cmds, m.loadPost(m.activePost, delay.(time.Duration)))
} else {
cmds = append(cmds, m.loadPost(m.activePost))
}
return true, cmds
}
return false, cmds
}
func handleWinFreshDataCmd(mi interface{}, c cmd.Command) (bool, []tea.Cmd) {
var m *Model = mi.(*Model)
var cmds []tea.Cmd

View File

@ -1,6 +1,8 @@
package postshow
import (
"time"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/glamour"
@ -80,7 +82,7 @@ func NewModel(c *ctx.Ctx) Model {
OnAnyUncaughtKey: handleUncaughtKeys,
OnViewResize: handleViewResize,
OnWinOpenCmd: handleWinOpenCmd,
OnWinRefreshDataCmd: handleWinOpenCmd,
OnWinRefreshDataCmd: handleWinRefreshDataCmd,
OnWinFreshDataCmd: handleWinFreshDataCmd,
})
@ -103,8 +105,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Batch(cmds...)
}
func (m *Model) loadPost(p *post.Post) tea.Cmd {
func (m *Model) loadPost(p *post.Post, delay ...time.Duration) tea.Cmd {
return func() tea.Msg {
if len(delay) == 1 {
time.Sleep(delay[0])
}
if err := m.a.LoadPost(p); err != nil {
m.ctx.Logger.Error(err)
c := cmd.New(