Rename a function

This commit is contained in:
Christian Rocha 2020-12-10 22:53:24 -05:00
parent 25dd530fb7
commit 64da53ede6
2 changed files with 26 additions and 27 deletions

View file

@ -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

View file

@ -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}
}