-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.go
50 lines (41 loc) · 1.22 KB
/
messages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
tea "github.com/charmbracelet/bubbletea"
"github.com/dominickp/hn/client"
)
func checkTopMenu(pageSize, page int) tea.Msg {
topMenuResponse, err := client.GetTopMenuResponse()
topMenuResponse.EnrichItems(pageSize, page)
if err != nil {
// There was an error making our request. Wrap the error we received
// in a message and return it.
return errMsg{err}
}
return topMenuMsg(topMenuResponse)
}
func checkTopMenuPage(topMenuResponse client.TopMenuResponse, pageSize, page int) tea.Msg {
topMenuResponse.EnrichItems(pageSize, page)
return checkTopMenuPageMsg(topMenuResponse)
}
func checkTopic(topicID int) tea.Msg {
item, err := client.GetItemWithComments(topicID, 10)
if err != nil {
// There was an error making our request. Wrap the error we received
// in a message and return it.
return errMsg{err}
}
// We received a response from the server. Return the HTTP status code
// as a message.
return topicMsg(item)
}
func checkNothing() tea.Msg {
return nil
}
type topMenuMsg client.TopMenuResponse
type topicMsg client.Item
type errMsg struct{ err error }
type checkTopMenuPageMsg client.TopMenuResponse
// Error implements error.
func (e errMsg) Error() string {
panic("unimplemented")
}