-
Notifications
You must be signed in to change notification settings - Fork 0
/
note_list.go
66 lines (53 loc) · 1.15 KB
/
note_list.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package component
import (
"github.com/maxence-charriere/go-app/v7/pkg/app"
"github.com/pelly-ryu/minim/app/internal"
)
type NoteList struct {
app.Compo
opened bool
}
func NewNoteList() *NoteList {
return &NoteList{
opened: false,
}
}
func (l *NoteList) Render() app.UI {
if !l.opened {
return app.Aside().ID("note-list").Class("closed").
OnClick(func(ctx app.Context, e app.Event) {
l.Toggle()
})
}
ids, err := internal.StorageListNoteId()
if err != nil {
panic(err)
}
var noteListEl []app.UI
for _, id := range ids {
n, err := internal.StorageGetNote(id)
if err != nil {
panic(err)
}
short := n.Body
if len(n.Body) > 50 {
short = n.Body[:50]
}
el := app.Div().Class("note-list-item note-list-item-selected").Body(
app.H5().Class("note-list-name").Text("Tilo Mitra"),
app.H4().Class("note-list-subject").Text(n.Title),
app.P().Class("note-list-desc").Text(short),
)
noteListEl = append(noteListEl, el)
}
return app.Aside().ID("note-list").Class("pure-u-1").Body(
noteListEl...
)
}
func (l *NoteList) Toggle() {
l.opened = !l.opened
l.Update()
}
func (l *NoteList) Opened() bool {
return l.opened
}