mirror of
https://github.com/mrusme/neonmodem.git
synced 2025-02-02 15:07:59 -05:00
Implemented draft post loading
This commit is contained in:
parent
d2f42ff754
commit
50e683f0fd
@ -8,6 +8,7 @@ const (
|
||||
WinOpen CallType = iota
|
||||
WinFocus
|
||||
WinBlur
|
||||
WinRefreshData
|
||||
|
||||
ViewFocus
|
||||
ViewBlur
|
||||
@ -55,3 +56,13 @@ func (cmd *Command) GetArg(name string) interface{} {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *Command) GetArgs() []Arg {
|
||||
var args []Arg
|
||||
|
||||
for name, value := range cmd.Args {
|
||||
args = append(args, Arg{Name: name, Value: value})
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
7
ui/ui.go
7
ui/ui.go
@ -74,6 +74,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
cmds := make([]tea.Cmd, 0)
|
||||
|
||||
switch msg := msg.(type) {
|
||||
|
||||
case tea.KeyMsg:
|
||||
switch {
|
||||
case key.Matches(msg, m.keymap.Close):
|
||||
@ -108,6 +109,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
msg.Target,
|
||||
postdialog.NewModel(m.ctx),
|
||||
[4]int{3, 2, 10, 6},
|
||||
msg.GetArgs()...,
|
||||
)
|
||||
m.ctx.Logger.Debugf("got back ccmds: %v\n", ccmds)
|
||||
default:
|
||||
@ -116,6 +118,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
cmds = append(cmds, ccmds...)
|
||||
|
||||
default:
|
||||
m.ctx.Logger.Debugf("updating all with default: %v\n", msg)
|
||||
cmds = append(cmds, m.wm.UpdateAll(msg)...)
|
||||
|
||||
}
|
||||
|
||||
v, vcmd := m.views[m.currentView].Update(msg)
|
||||
|
@ -23,7 +23,7 @@ func New() *WM {
|
||||
return wm
|
||||
}
|
||||
|
||||
func (wm *WM) Open(id string, win windows.Window, xywh [4]int) []tea.Cmd {
|
||||
func (wm *WM) Open(id string, win windows.Window, xywh [4]int, args ...cmd.Arg) []tea.Cmd {
|
||||
var tcmds []tea.Cmd
|
||||
|
||||
if wm.IsOpen(id) {
|
||||
@ -44,6 +44,11 @@ func (wm *WM) Open(id string, win windows.Window, xywh [4]int) []tea.Cmd {
|
||||
Width: item.XYWH[2],
|
||||
Height: item.XYWH[3],
|
||||
}))
|
||||
tcmds = append(tcmds, wm.Update(id, *cmd.New(
|
||||
cmd.WinRefreshData,
|
||||
id,
|
||||
args...,
|
||||
)))
|
||||
|
||||
fcmds := wm.Focus(id)
|
||||
tcmds = append(tcmds, fcmds...)
|
||||
|
@ -154,13 +154,23 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// cmds = append(cmds, viewport.Sync(m.viewport))
|
||||
|
||||
case *post.Post:
|
||||
m.viewport.SetContent(m.renderViewport(msg))
|
||||
m.ctx.Logger.Debug("got *post.Post")
|
||||
m.activePost = msg
|
||||
m.viewport.SetContent(m.renderViewport(m.activePost))
|
||||
m.ctx.Loading = false
|
||||
return m, nil
|
||||
|
||||
case cmd.Command:
|
||||
m.ctx.Logger.Debugf("got command: %v\n", msg)
|
||||
switch msg.Call {
|
||||
case cmd.WinRefreshData:
|
||||
if msg.Target == "post" {
|
||||
m.activePost = msg.GetArg("post").(*post.Post)
|
||||
m.ctx.Logger.Debugf("loading post: %v", m.activePost.ID)
|
||||
m.ctx.Loading = true
|
||||
return m, m.loadPost(m.activePost)
|
||||
}
|
||||
return m, nil
|
||||
case cmd.WinFocus:
|
||||
if msg.Target == "post" {
|
||||
m.focused = true
|
||||
@ -171,6 +181,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.focused = false
|
||||
}
|
||||
return m, nil
|
||||
default:
|
||||
m.ctx.Logger.Debugf("received unhandled command: %v\n", msg)
|
||||
}
|
||||
|
||||
default:
|
||||
@ -185,6 +197,16 @@ 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 {
|
||||
return func() tea.Msg {
|
||||
m.ctx.Logger.Debug("------ EXECUTED -----")
|
||||
if err := m.a.LoadPost(p); err != nil {
|
||||
m.ctx.Logger.Error(err)
|
||||
}
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
func (m Model) View() string {
|
||||
return m.buildView(true)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user