apps/jotts/tui/commands.go 849 B raw
1
package tui
2
3
import (
4
	"strings"
5
6
	tea "charm.land/bubbletea/v2"
7
)
8
9
func loadNotesCmd(b Backend) tea.Cmd {
10
	return func() tea.Msg {
11
		notes, err := b.List()
12
		return notesLoadedMsg{Notes: notes, Err: err}
13
	}
14
}
15
16
func saveNoteCmd(b Backend, shortID, title, content string) tea.Cmd {
17
	return func() tea.Msg {
18
		var (
19
			note *Note
20
			err  error
21
		)
22
		if shortID == "" {
23
			note, err = b.Create(title, content)
24
		} else {
25
			note, err = b.Update(shortID, title, content)
26
		}
27
		return noteSavedMsg{Note: note, Err: err}
28
	}
29
}
30
31
func deleteNoteCmd(b Backend, shortID string) tea.Cmd {
32
	return func() tea.Msg {
33
		_, err := b.Delete(shortID)
34
		return noteDeletedMsg{ShortID: shortID, Err: err}
35
	}
36
}
37
38
func noteLinkURL(remoteBase, shortID string) string {
39
	if remoteBase == "" {
40
		return ""
41
	}
42
	return strings.TrimRight(remoteBase, "/") + "/notes/" + shortID
43
}