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

78 lines
1.6 KiB
Go
Raw Normal View History

2023-01-03 16:46:16 -05:00
package postcreate
import (
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/mrusme/gobbs/models/post"
2023-01-03 16:46:16 -05:00
"github.com/mrusme/gobbs/ui/helpers"
)
func (m Model) View() string {
return m.tk.View(&m, true)
}
func buildView(mi interface{}, cached bool) string {
var m *Model = mi.(*Model)
if cached && m.viewcache != "" {
m.ctx.Logger.Debugln("Cached View()")
m.textarea.SetWidth(m.viewcacheTextareaXY[2])
m.textarea.SetHeight(m.viewcacheTextareaXY[3])
return helpers.PlaceOverlay(
m.viewcacheTextareaXY[0], m.viewcacheTextareaXY[1],
m.textarea.View(), m.viewcache,
false)
}
title := ""
if m.action == "reply" {
title = "Reply"
if m.replyToIdx != 0 {
title += fmt.Sprintf(" to reply #%d", m.replyToIdx)
}
} else if m.action == "post" {
p := m.iface.(*post.Post)
sysTitle := (*m.ctx.Systems[p.SysIDX]).Title()
title = fmt.Sprintf("New Post in %s on %s", p.Forum.Name, sysTitle)
2023-01-03 16:46:16 -05:00
}
// textinputWidth := m.tk.ViewWidth() - 2
// m.textinput.SetWidth(textinputWidth)
2023-01-03 16:46:16 -05:00
textareaWidth := m.tk.ViewWidth() - 2
textareaHeight := 6
m.textarea.SetWidth(textareaWidth)
m.textarea.SetHeight(textareaHeight)
m.viewcacheTextareaXY[0] = 1
m.viewcacheTextareaXY[1] = 2
m.viewcacheTextareaXY[2] = textareaWidth
m.viewcacheTextareaXY[3] = textareaHeight
m.ctx.Logger.Debugln("View()")
m.ctx.Logger.Debugf("IsFocused: %v\n", m.tk.IsFocused())
var tmp string = ""
if m.action == "post" {
tmp = lipgloss.JoinVertical(
lipgloss.Left,
m.textinput.View(),
"",
m.textarea.View(),
)
} else if m.action == "reply" {
tmp = m.textarea.View()
}
2023-01-03 16:46:16 -05:00
return m.tk.Dialog(
title,
tmp,
2023-01-04 21:41:13 -05:00
true,
2023-01-03 16:46:16 -05:00
)
}