-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentModel.go
More file actions
79 lines (65 loc) · 1.53 KB
/
Copy pathcontentModel.go
File metadata and controls
79 lines (65 loc) · 1.53 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
tea "github.com/charmbracelet/bubbletea"
)
type ContentModel struct {
libraryModel tea.Model
queueModel tea.Model
albumModel tea.Model
}
func initContentModel() ContentModel {
return ContentModel{
libraryModel: initLibraryModel(),
queueModel: initQueueModel(),
albumModel: initAlbumModel(),
}
}
func (m ContentModel) Init() tea.Cmd {
return tea.Batch(
m.libraryModel.Init(),
m.queueModel.Init(),
m.albumModel.Init(),
)
}
func (m ContentModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
cmds := []tea.Cmd{}
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "1":
currentContentFocus = libraryFocus
case "2":
currentContentFocus = queueFocus
}
switch currentContentFocus {
case libraryFocus:
m.libraryModel, cmd = m.libraryModel.Update(msg)
case queueFocus:
m.queueModel, cmd = m.queueModel.Update(msg)
case albumFocus:
m.albumModel, cmd = m.albumModel.Update(msg)
}
cmds = append(cmds, cmd)
return m, tea.Batch(cmds...)
}
m.libraryModel, cmd = m.libraryModel.Update(msg)
cmds = append(cmds, cmd)
m.queueModel, cmd = m.queueModel.Update(msg)
cmds = append(cmds, cmd)
m.albumModel, cmd = m.albumModel.Update(msg)
cmds = append(cmds, cmd)
return m, tea.Batch(cmds...)
}
func (m ContentModel) View() string {
output := ""
switch currentContentFocus {
case libraryFocus:
output = m.libraryModel.View()
case queueFocus:
output = m.queueModel.View()
case albumFocus:
output = m.albumModel.View()
}
return output
}