get updating posts working
This commit is contained in:
parent
972707e5fd
commit
6b8ba76018
6 changed files with 148 additions and 53 deletions
|
|
@ -20,15 +20,6 @@ func initialEntryPageModel() EntryPageModel {
|
|||
return EntryPageModel{}
|
||||
}
|
||||
|
||||
func transformEntryToContent(entry gemlog.GemlogEntry) string {
|
||||
content := entry.Slug
|
||||
content += "\n\n"
|
||||
content += entry.Gemtxt
|
||||
content += "\n\n-------------------------\n"
|
||||
content += "\n\nPress h or left arrow to go back"
|
||||
return content
|
||||
}
|
||||
|
||||
func (m EntryPageModel) Update(msg tea.Msg, active bool, ctx *context) (EntryPageModel, tea.Cmd) {
|
||||
var (
|
||||
cmd tea.Cmd
|
||||
|
|
@ -37,7 +28,7 @@ func (m EntryPageModel) Update(msg tea.Msg, active bool, ctx *context) (EntryPag
|
|||
switch msg := msg.(type) {
|
||||
case GemLogLoaded:
|
||||
m.entry = msg.Log
|
||||
m.viewport.SetContent(transformEntryToContent(m.entry))
|
||||
m.viewport.SetContent(m.entry.Gemtxt)
|
||||
case tea.KeyMsg:
|
||||
if !active {
|
||||
return m, nil
|
||||
|
|
@ -50,7 +41,7 @@ func (m EntryPageModel) Update(msg tea.Msg, active bool, ctx *context) (EntryPag
|
|||
return m, cmd
|
||||
}
|
||||
case tea.WindowSizeMsg:
|
||||
headerHeight := lipgloss.Height(m.headerView())
|
||||
headerHeight := lipgloss.Height(m.headerView("loading slug..."))
|
||||
footerHeight := lipgloss.Height(m.footerView())
|
||||
verticalMarginHeight := headerHeight + footerHeight
|
||||
|
||||
|
|
@ -63,7 +54,7 @@ func (m EntryPageModel) Update(msg tea.Msg, active bool, ctx *context) (EntryPag
|
|||
|
||||
m.viewport = viewport.New(msg.Width, msg.Height-verticalMarginHeight)
|
||||
m.viewport.YPosition = headerHeight
|
||||
m.viewport.SetContent(transformEntryToContent(m.entry))
|
||||
m.viewport.SetContent(m.entry.Gemtxt)
|
||||
m.ready = true
|
||||
} else {
|
||||
m.viewport.Width = msg.Width
|
||||
|
|
@ -83,7 +74,7 @@ func (m EntryPageModel) View() string {
|
|||
return "\n Initializing..."
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s\n%s\n%s", m.headerView(), m.viewport.View(), m.footerView())
|
||||
return fmt.Sprintf("%s\n%s\n%s", m.headerView(m.entry.Slug), m.viewport.View(), m.footerView())
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -100,8 +91,8 @@ var (
|
|||
}()
|
||||
)
|
||||
|
||||
func (m EntryPageModel) headerView() string {
|
||||
title := titleStyle.Render("Mr. Pager")
|
||||
func (m EntryPageModel) headerView(slug string) string {
|
||||
title := titleStyle.Render(slug)
|
||||
line := strings.Repeat("─", max(0, m.viewport.Width-lipgloss.Width(title)))
|
||||
return lipgloss.JoinHorizontal(lipgloss.Center, title, line)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue