diff --git a/ui/stash.go b/ui/stash.go index 6995907..c698ce8 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -1194,7 +1194,7 @@ func (m stashModel) populatedView() string { // loadRemoteMarkdown is a command for loading markdown from the server. func loadRemoteMarkdown(cc *charm.Client, md *markdown) tea.Cmd { return func() tea.Msg { - newMD, err := loadMarkdownFromCharm(cc, md.ID, md.markdownType) + newMD, err := fetchMarkdown(cc, md.ID, md.markdownType) if err != nil { if debug { log.Printf("error loading %s markdown (ID %d, Note: '%s'): %v", md.markdownType, md.ID, md.Note, err) @@ -1210,31 +1210,6 @@ func loadRemoteMarkdown(cc *charm.Client, md *markdown) tea.Cmd { } } -// loadMarkdownFromCharm performs the actual I/O for loading markdown from the -// sever. -func loadMarkdownFromCharm(cc *charm.Client, id int, t DocType) (*markdown, error) { - var md *charm.Markdown - var err error - - switch t { - case StashedDoc, ConvertedDoc: - md, err = cc.GetStashMarkdown(id) - case NewsDoc: - md, err = cc.GetNewsMarkdown(id) - default: - err = fmt.Errorf("unknown markdown type: %s", t) - } - - if err != nil { - return nil, err - } - - return &markdown{ - markdownType: t, - Markdown: *md, - }, nil -} - func loadLocalMarkdown(md *markdown) tea.Cmd { return func() tea.Msg { if md.markdownType != LocalDoc { @@ -1296,6 +1271,30 @@ func filterMarkdowns(m stashModel) tea.Cmd { // ETC +// fetchMarkdown performs the actual I/O for loading markdown from the sever. +func fetchMarkdown(cc *charm.Client, id int, t DocType) (*markdown, error) { + var md *charm.Markdown + var err error + + switch t { + case StashedDoc, ConvertedDoc: + md, err = cc.GetStashMarkdown(id) + case NewsDoc: + md, err = cc.GetNewsMarkdown(id) + default: + err = fmt.Errorf("unknown markdown type: %s", t) + } + + if err != nil { + return nil, err + } + + return &markdown{ + markdownType: t, + Markdown: *md, + }, nil +} + // Delete a markdown from a slice of markdowns. func deleteMarkdown(markdowns []*markdown, target *markdown) ([]*markdown, error) { index := -1 diff --git a/ui/ui.go b/ui/ui.go index 29a1608..4471b90 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -658,7 +658,7 @@ func stashDocument(cc *charm.Client, md markdown) tea.Cmd { md.Body = string(data) case NewsDoc: - newMD, err := loadMarkdownFromCharm(cc, md.ID, md.markdownType) + newMD, err := fetchMarkdown(cc, md.ID, md.markdownType) if err != nil { return stashFailMsg{err, md} }