From 251aacf79a867a1caa0f842b79f04fe049c0bc9e Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Fri, 22 May 2020 16:01:23 -0400 Subject: [PATCH] Fix markdown sorting error --- ui/stash.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ui/stash.go b/ui/stash.go index 5c2ba19..edcc814 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -141,6 +141,13 @@ func (m stashModel) markdownIndex() int { return m.paginator.Page*m.paginator.PerPage + m.index } +// addMarkdowns adds markdown documents to the model +func (m *stashModel) addMarkdowns(mds ...*markdown) { + m.documents = append(m.documents, mds...) + sort.Sort(markdownsByCreatedAtDesc(m.documents)) + m.paginator.SetTotalPages(len(m.documents)) +} + // INIT func stashInit(cc *charm.Client) (stashModel, boba.Cmd) { @@ -197,9 +204,7 @@ func stashUpdate(msg boba.Msg, m stashModel) (stashModel, boba.Cmd) { } docs := wrapMarkdowns(userMarkdown, msg) - sort.Sort(markdownsByCreatedAtDesc(docs)) // sort by date - m.documents = append(m.documents, docs...) - m.paginator.SetTotalPages(len(m.documents)) + m.addMarkdowns(docs...) m.loaded |= loadedStash if m.loaded.done() { @@ -209,9 +214,7 @@ func stashUpdate(msg boba.Msg, m stashModel) (stashModel, boba.Cmd) { case gotNewsMsg: if len(msg) > 0 { docs := wrapMarkdowns(newsMarkdown, msg) - sort.Sort(markdownsByCreatedAtDesc(docs)) - m.documents = append(m.documents, docs...) - m.paginator.SetTotalPages(len(m.documents)) + m.addMarkdowns(docs...) } m.loaded |= loadedNews