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

Implemented # reply

This commit is contained in:
マリウス 2023-01-01 03:13:08 -05:00
parent 7fa6953064
commit fe97aad5b5
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F

View File

@ -60,7 +60,9 @@ type Model struct {
glam *glamour.TermRenderer glam *glamour.TermRenderer
focused string focused string
buffer string
replyIDs []string
} }
func (m Model) Init() tea.Cmd { func (m Model) Init() tea.Cmd {
@ -74,6 +76,7 @@ func NewModel(c *ctx.Ctx) Model {
ctx: c, ctx: c,
keymap: DefaultKeyMap, keymap: DefaultKeyMap,
focused: "list", focused: "list",
buffer: "",
} }
listDelegate := list.NewDefaultDelegate() listDelegate := list.NewDefaultDelegate()
@ -129,8 +132,22 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil return m, nil
} else if m.focused == "reply" { } else if m.focused == "reply" {
m.focused = "post" m.focused = "post"
m.buffer = ""
return m, nil return m, nil
} }
default:
switch msg.String() {
case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0":
if m.focused == "post" {
m.buffer += msg.String()
return m, nil
}
default:
if m.focused != "reply" {
m.buffer = ""
}
}
} }
case tea.WindowSizeMsg: case tea.WindowSizeMsg:
@ -211,7 +228,7 @@ func (m Model) View() string {
bottombar := m.ctx.Theme.DialogBox.Bottombar. bottombar := m.ctx.Theme.DialogBox.Bottombar.
Width(m.viewport.Width + 4). Width(m.viewport.Width + 4).
Render("r reply · esc close") Render("[#]r reply · esc close")
ui := lipgloss.JoinVertical( ui := lipgloss.JoinVertical(
lipgloss.Center, lipgloss.Center,
@ -236,10 +253,14 @@ func (m Model) View() string {
} }
if m.focused == "reply" { if m.focused == "reply" {
title := "Reply"
if m.buffer != "" && m.buffer != "0" {
title += " to reply #" + m.buffer
}
titlebar := m.ctx.Theme.DialogBox.Titlebar.Focused. titlebar := m.ctx.Theme.DialogBox.Titlebar.Focused.
Align(lipgloss.Center). Align(lipgloss.Center).
Width(m.viewport.Width - 2). Width(m.viewport.Width - 2).
Render("Reply") Render(title)
m.textarea.SetWidth(m.viewport.Width - 2) m.textarea.SetWidth(m.viewport.Width - 2)
m.textarea.SetHeight(6) m.textarea.SetHeight(6)
@ -321,7 +342,8 @@ func (m *Model) renderViewport(p *post.Post) string {
body, body,
) )
out += m.renderReplies(0, 1, p.Author.Name, &p.Replies) m.replyIDs = []string{p.ID}
out += m.renderReplies(0, p.Author.Name, &p.Replies)
m.focused = "post" m.focused = "post"
return out return out
@ -329,7 +351,6 @@ func (m *Model) renderViewport(p *post.Post) string {
func (m *Model) renderReplies( func (m *Model) renderReplies(
level int, level int,
idx int,
inReplyTo string, inReplyTo string,
replies *[]reply.Reply, replies *[]reply.Reply,
) string { ) string {
@ -356,6 +377,10 @@ func (m *Model) renderReplies(
author = re.Author.Name author = re.Author.Name
} }
m.replyIDs = append(m.replyIDs, re.ID)
idx := len(m.replyIDs) - 1
out += fmt.Sprintf( out += fmt.Sprintf(
"\n\n %s %s%s%s\n%s", "\n\n %s %s%s%s\n%s",
m.ctx.Theme.Reply.Author.Render( m.ctx.Theme.Reply.Author.Render(
@ -372,7 +397,7 @@ func (m *Model) renderReplies(
) )
idx++ idx++
out += m.renderReplies(level+1, idx, re.Author.Name, &re.Replies) out += m.renderReplies(level+1, re.Author.Name, &re.Replies)
} }
return out return out