1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-12-04 14:46:37 -05:00

Implemented reply feature

This commit is contained in:
マリウス 2023-01-02 20:34:39 -05:00
parent 0e987d1e4f
commit 4a9ed09782
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
4 changed files with 84 additions and 52 deletions

View File

@ -18,6 +18,8 @@ const (
ViewFreshData ViewFreshData
MsgError MsgError
WMCloseWin
) )
type Arg struct { type Arg struct {

View File

@ -115,6 +115,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var ccmds []tea.Cmd var ccmds []tea.Cmd
switch msg.Call { switch msg.Call {
case cmd.WinOpen: case cmd.WinOpen:
switch msg.Target { switch msg.Target {
case postshow.WIN_ID: case postshow.WIN_ID:
@ -137,12 +138,19 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
) )
} }
m.ctx.Logger.Debugf("got back ccmds: %v\n", ccmds) m.ctx.Logger.Debugf("got back ccmds: %v\n", ccmds)
case cmd.WinClose: case cmd.WinClose:
switch msg.Target { switch msg.Target {
case postcreate.WIN_ID: case postcreate.WIN_ID:
m.ctx.Logger.Debugln("received WinClose") m.ctx.Logger.Debugln("received WinClose")
m.renderOnlyFocused = false m.renderOnlyFocused = false
} }
case cmd.WMCloseWin:
if ok, clcmds := m.wm.Close(msg.Target); ok {
cmds = append(cmds, clcmds...)
}
default: default:
if msg.Call < cmd.ViewFocus { if msg.Call < cmd.ViewFocus {
m.ctx.Logger.Debugf("updating all with cmd: %v\n", msg) m.ctx.Logger.Debugf("updating all with cmd: %v\n", msg)

View File

@ -2,6 +2,7 @@ package postcreate
import ( import (
"fmt" "fmt"
"strconv"
"strings" "strings"
"github.com/charmbracelet/bubbles/cursor" "github.com/charmbracelet/bubbles/cursor"
@ -48,8 +49,9 @@ type Model struct {
a *aggregator.Aggregator a *aggregator.Aggregator
glam *glamour.TermRenderer glam *glamour.TermRenderer
activeReply *reply.Reply replyToIdx int
replyToIdx int replyTo string
replyToIface interface{}
viewcache string viewcache string
viewcacheTextareaXY []int viewcacheTextareaXY []int
@ -74,7 +76,9 @@ func NewModel(c *ctx.Ctx) Model {
focused: false, focused: false,
xywh: [4]int{0, 0, 0, 0}, xywh: [4]int{0, 0, 0, 0},
replyToIdx: 0, replyToIdx: 0,
replyTo: "",
replyToIface: nil,
viewcache: "", viewcache: "",
viewcacheTextareaXY: []int{0, 0, 0, 0}, viewcacheTextareaXY: []int{0, 0, 0, 0},
@ -97,39 +101,38 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch { switch {
case key.Matches(msg, m.keymap.Reply): case key.Matches(msg, m.keymap.Reply):
// replyToIdx, _ := strconv.Atoi(m.buffer)
// var irtID string = ""
// m.ctx.Logger.Debugf("replyToIdx: %d", replyToIdx) var irtIRT string = ""
// var irtSysIDX int = 0
// var irtID string = ""
// var irtIRT string = "" if m.replyToIdx == 0 {
// var irtSysIDX int = 0 pst := m.replyToIface.(post.Post)
// irtID = pst.ID
// if replyToIdx == 0 { irtSysIDX = pst.SysIDX
// irtID = m.activePost.ID } else {
// irtSysIDX = m.activePost.SysIDX rply := m.replyToIface.(reply.Reply)
// } else { irtID = strconv.Itoa(m.replyToIdx + 1)
// irt := m.allReplies[(replyToIdx - 1)] irtIRT = rply.InReplyTo
// irtID = strconv.Itoa(replyToIdx + 1) irtSysIDX = rply.SysIDX
// irtIRT = irt.InReplyTo }
// irtSysIDX = irt.SysIDX
// } r := reply.Reply{
// ID: irtID,
// r := reply.Reply{ InReplyTo: irtIRT,
// ID: irtID, Body: m.textarea.Value(),
// InReplyTo: irtIRT, SysIDX: irtSysIDX,
// Body: m.textarea.Value(), }
// SysIDX: irtSysIDX,
// } err := m.a.CreateReply(&r)
// err := m.a.CreateReply(&r) if err != nil {
// if err != nil { m.ctx.Logger.Error(err)
// m.ctx.Logger.Error(err) // TODO
// } }
//
// m.textarea.Reset() m.textarea.Reset()
// m.buffer = "" m.replyToIdx = 0
// m.WMClose("reply") return m, cmd.New(cmd.WMCloseWin, WIN_ID).Tea()
// return m, nil
} }
@ -144,6 +147,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case cmd.WinOpen: case cmd.WinOpen:
if msg.Target == WIN_ID { if msg.Target == WIN_ID {
m.xywh = msg.GetArg("xywh").([4]int) m.xywh = msg.GetArg("xywh").([4]int)
m.replyToIdx = msg.GetArg("replyToIdx").(int)
m.replyTo = msg.GetArg("replyTo").(string)
m.replyToIface = msg.GetArg(m.replyTo)
return m, m.textarea.Focus() return m, m.textarea.Focus()
} }
case cmd.WinClose: case cmd.WinClose:
@ -250,7 +256,5 @@ func (m Model) buildView(cached bool) string {
view = strings.Builder{} view = strings.Builder{}
view.WriteString(tmp) view.WriteString(tmp)
// m.viewcache = view.String()
// return m.viewcache
return view.String() return view.String()
} }

View File

@ -2,6 +2,7 @@ package postshow
import ( import (
"fmt" "fmt"
"strconv"
"strings" "strings"
"github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/key"
@ -97,22 +98,39 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch { switch {
case key.Matches(msg, m.keymap.Reply): case key.Matches(msg, m.keymap.Reply):
// if m.buffer != "" { var replyToIdx int = 0
// replyToID, err := strconv.Atoi(m.buffer) var err error
// if err != nil {
// // TODO: Handle error
// }
//
// if replyToID >= len(m.replyIDs) {
// // TODO: Handle error
// }
// }
m.viewcache = m.buildView(false) m.viewcache = m.buildView(false)
cmd := cmd.New(cmd.WinOpen, postcreate.WIN_ID, cmd.Arg{ if m.buffer != "" {
Name: "post", replyToIdx, err = strconv.Atoi(m.buffer)
Value: &m.activePost,
}) if err != nil {
// TODO: Handle error
}
if replyToIdx >= len(m.replyIDs) {
// TODO: Handle error
}
}
m.ctx.Logger.Debugf("replyToIdx: %d", replyToIdx)
var rtype cmd.Arg = cmd.Arg{Name: "replyTo"}
var rarg cmd.Arg
var ridx cmd.Arg = cmd.Arg{Name: "replyToIdx", Value: replyToIdx}
if replyToIdx == 0 {
rtype.Value = "post"
rarg.Name = "post"
rarg.Value = *m.activePost
} else {
rtype.Value = "reply"
rarg.Name = "reply"
rarg.Value = *m.allReplies[(replyToIdx - 1)]
}
cmd := cmd.New(cmd.WinOpen, postcreate.WIN_ID, rtype, rarg, ridx)
cmds = append(cmds, cmd.Tea()) cmds = append(cmds, cmd.Tea())
m.ctx.Logger.Debugln("caching view") m.ctx.Logger.Debugln("caching view")