diff --git a/ui/stash.go b/ui/stash.go index fd9e4f0..25c4b21 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -67,6 +67,7 @@ const ( stashStateShowingError stashStateFilterNotes stashStateShowFiltered + stashStateShowNews ) type stashModel struct { @@ -264,6 +265,16 @@ func (m stashModel) countMarkdowns(t markdownType) (found int) { } func (m stashModel) getVisibleMarkdowns() []*markdown { + if m.state == stashStateShowNews { + news := []*markdown{} + for _, md := range m.markdowns { + // TODO: Sort news according to their CreatedAt date + if md.markdownType == newsMarkdown { + news = append(news, md) + } + } + return news + } if m.isFiltering() { return m.filteredMarkdowns } @@ -486,7 +497,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { } switch m.state { - case stashStateReady, stashStateShowFiltered: + case stashStateReady, stashStateShowFiltered, stashStateShowNews: pages := len(m.getVisibleMarkdowns()) switch msg := msg.(type) { @@ -509,7 +520,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { m.paginator.Page = m.paginator.TotalPages - 1 m.index = m.paginator.ItemsOnPage(pages) - 1 - // Note: esc is only passed trough in stashStateFilterNotes + // Note: esc is only passed trough in stashStateFilterNotes and stashStateShowNews case "esc": m.state = stashStateReady m.resetFiltering() @@ -529,6 +540,10 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { // Filter your notes case "/": + if m.state == stashStateShowNews { + break + } + m.hideStatusMessage() // Build values we'll filter against @@ -565,6 +580,15 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { return m, textinput.Blink } + // News + case "n": + m.hideStatusMessage() + m.paginator.Page = 0 + m.index = 0 + m.state = stashStateShowNews + m.setTotalPages() + return m, nil + // Stash case "s": if pages == 0 || m.general.authStatus != authOK || m.selectedMarkdown() == nil { @@ -817,7 +841,7 @@ func stashView(m stashModel) string { return errorView(m.err, false) case stashStateLoadingDocument: s += " " + m.spinner.View() + " Loading document..." - case stashStateReady, stashStateSettingNote, stashStatePromptDelete, stashStateFilterNotes, stashStateShowFiltered: + case stashStateReady, stashStateSettingNote, stashStatePromptDelete, stashStateFilterNotes, stashStateShowFiltered, stashStateShowNews: loadingIndicator := " " if !m.localOnly() && (!m.loadingDone() || m.loadingFromNetwork || m.spinner.Visible()) { @@ -855,6 +879,8 @@ func stashView(m stashModel) string { // If we're filtering we replace the logo with the filter field if m.state == stashStateFilterNotes || m.state == stashStateShowFiltered { logoOrFilter = m.filterInput.View() + } else if m.state == stashStateShowNews { + logoOrFilter = glowLogoView(" Newsfeed ") } var pagination string @@ -1012,6 +1038,8 @@ func stashHelpView(m stashModel) string { h = append(h, "enter/esc: cancel") } else if m.state == stashStateFilterNotes { h = append(h, "enter: confirm", "esc: cancel", "ctrl+j/ctrl+k, ↑/↓: choose") + } else if m.state == stashStateShowNews { + h = append(h, "enter: open", "esc: return", "j/k, ↑/↓: choose", "q: quit") } else { if len(m.markdowns) > 0 { h = append(h, "enter: open") diff --git a/ui/ui.go b/ui/ui.go index 12c31df..d46a112 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -253,13 +253,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // Send q/esc through in these cases case stashStateSettingNote, stashStatePromptDelete, stashStateShowingError, stashStateFilterNotes, - stashStateShowFiltered: + stashStateShowFiltered, stashStateShowNews: // If we're fitering, only send esc through so we can clear // the filter results. Q quits as normal. if m.stash.state == stashStateShowFiltered && msg.String() == "q" { return m, tea.Quit } + // Q also quits glow when displaying only newsitems + if m.stash.state == stashStateShowNews && msg.String() == "q" { + return m, tea.Quit + } m.stash, cmd = stashUpdate(msg, m.stash) return m, cmd