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

Refactored viewportOpen

This commit is contained in:
マリウス 2022-12-31 17:24:22 -05:00
parent c2f13b5d5a
commit 6b63fc44c2
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F

View File

@ -58,7 +58,7 @@ type Model struct {
glam *glamour.TermRenderer glam *glamour.TermRenderer
viewportOpen bool focused string
} }
func (m Model) Init() tea.Cmd { func (m Model) Init() tea.Cmd {
@ -67,8 +67,8 @@ func (m Model) Init() tea.Cmd {
func NewModel(c *ctx.Ctx) Model { func NewModel(c *ctx.Ctx) Model {
m := Model{ m := Model{
keymap: DefaultKeyMap, keymap: DefaultKeyMap,
viewportOpen: false, focused: "list",
} }
m.list = list.New(m.items, list.NewDefaultDelegate(), 0, 0) m.list = list.New(m.items, list.NewDefaultDelegate(), 0, 0)
@ -98,8 +98,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} }
case key.Matches(msg, m.keymap.Close): case key.Matches(msg, m.keymap.Close):
if m.viewportOpen { if m.focused == "post" {
m.viewportOpen = false m.focused = "list"
return m, nil return m, nil
} }
} }
@ -140,10 +140,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd var cmd tea.Cmd
if m.viewportOpen { if m.focused == "list" {
m.viewport, cmd = m.viewport.Update(msg)
} else if m.viewportOpen == true {
m.list, cmd = m.list.Update(msg) m.list, cmd = m.list.Update(msg)
} else if m.focused == "post" {
m.viewport, cmd = m.viewport.Update(msg)
} }
cmds = append(cmds, cmd) cmds = append(cmds, cmd)
@ -154,17 +154,17 @@ func (m Model) View() string {
var view strings.Builder = strings.Builder{} var view strings.Builder = strings.Builder{}
var l string = "" var l string = ""
if m.viewportOpen { if m.focused == "list" {
l = m.ctx.Theme.PostsList.List.Blurred.Render(m.list.View())
} else {
l = m.ctx.Theme.PostsList.List.Focused.Render(m.list.View()) l = m.ctx.Theme.PostsList.List.Focused.Render(m.list.View())
} else {
l = m.ctx.Theme.PostsList.List.Blurred.Render(m.list.View())
} }
view.WriteString(lipgloss.JoinHorizontal( view.WriteString(lipgloss.JoinHorizontal(
lipgloss.Top, lipgloss.Top,
l, l,
)) ))
if m.viewportOpen { if m.focused == "post" {
titlebar := m.ctx.Theme.DialogBox.Titlebar. titlebar := m.ctx.Theme.DialogBox.Titlebar.
Align(lipgloss.Center). Align(lipgloss.Center).
Width(m.viewport.Width + 4). Width(m.viewport.Width + 4).
@ -246,7 +246,7 @@ func (m *Model) renderViewport(p *post.Post) string {
out += m.renderReplies(0, p.Author.Name, &p.Replies) out += m.renderReplies(0, p.Author.Name, &p.Replies)
m.viewportOpen = true m.focused = "post"
return out return out
} }