add subscriptions viewer

nbsp 2025-01-07 14:25:35 +02:00
parent 4ca3c30ee7
commit adf0978709
No known key found for this signature in database
GPG Key ID: 7184AC1C9835CE48
6 changed files with 110 additions and 15 deletions

1
.nanparc 100644
View File

@ -0,0 +1 @@
version 0.1.0

View File

@ -14,16 +14,15 @@ make
- [x] main menu
- [x] credits
- [ ] feels browser
- [ ] configuration editor
- [x] feels publishing
- [x] feels browser
- [x] configuration editor
- [ ] feels manager
- [ ] feels publishing
- [x] plaintext
- [ ] html
- [ ] gopher
- [ ] graffiti
- [ ] feedback
- [ ] documentation with manpages
nice-to-haves:
- [ ] mouse support
- [ ] image support via sixels
- [x] documentation with manpages
## contributing

View File

@ -32,8 +32,8 @@ func NewMainMenu() *MainMenu {
"manage your feels",
"check out your neighbors",
"browse global feels",
"visit your subscriptions", // TODO
"scribble some graffiti", // TODO
"visit your subscriptions",
"scribble some graffiti", // TODO
"change your settings",
"see credits",
"read documentation",
@ -68,6 +68,8 @@ func (menu *MainMenu) Event(state *ui.State, event vaxis.Event) (processed bool)
ui.ViewChange <- NewNeighbors()
case 3:
ui.ViewChange <- NewBrowse()
case 4:
ui.ViewChange <- NewSubscriptions()
case 6:
ui.ViewChange <- NewConfig()
case 7:

View File

@ -22,15 +22,17 @@ func NewNeighbors() *Neighbors {
users := ttbp.SortUsersByRecent(ttbp.GetUsers())
subscriptions := ttbp.GetSubscriptions()
list := []string{}
neighbors := []ttbp.User{}
for _, user := range users {
list = append(list, formatNeighbor(user, subscriptions))
neighbors = append(neighbors, user)
}
return &Neighbors{
title,
ui.NewList(list),
"↑↓/kj move ↵ enter s subscribe q return",
users,
neighbors,
subscriptions,
}
}
@ -78,6 +80,7 @@ func (neighbors *Neighbors) Event(state *ui.State, event vaxis.Event) (processed
} else {
neighbors.subscriptions.Subscribe(user)
}
neighbors.subscriptions.Write()
neighbors.list.SetItem(neighbors.list.Index(), formatNeighbor(user, neighbors.subscriptions))
case "Enter", "l", "Right":
ui.ViewChange <- NewUserPage(neighbors.neighbors[neighbors.list.Index()].Name)

View File

@ -0,0 +1,92 @@
package app
import (
"strconv"
"git.sr.ht/~rockorager/vaxis"
"git.tilde.town/nbsp/neofeels/ttbp"
"git.tilde.town/nbsp/neofeels/ui"
)
type Subscriptions struct {
title string
list ui.List
help string
neighbors []ttbp.User
subscriptions *ttbp.Subscriptions
}
func NewSubscriptions() *Subscriptions {
users := ttbp.SortUsersByRecent(ttbp.GetUsers())
subscriptions := ttbp.GetSubscriptions()
list := []string{}
for _, user := range users {
if subscriptions.IsSubscribed(user) {
list = append(list, formatNeighbor(user, subscriptions))
}
}
return &Subscriptions{
title,
ui.NewList(list),
"↑↓/kj move ↵ enter s subscribe q return",
users,
subscriptions,
}
}
func (subscriptions *Subscriptions) Event(state *ui.State, event vaxis.Event) (processed bool) {
if key, ok := event.(vaxis.Key); ok && key.EventType == vaxis.EventPress {
switch key.String() {
case "Ctrl+c", "Ctrl+d":
close(ui.Quit)
case "Down", "j":
subscriptions.list.Down()
case "Up", "k":
subscriptions.list.Up()
case "End", "Shift+g":
subscriptions.list.End()
case "Home", "g":
subscriptions.list.Home()
case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9":
i, _ := strconv.Atoi(key.String())
subscriptions.list.SetIndex(i)
case "q", "h", "Left":
subscriptions.subscriptions.Write()
ui.ViewChange <- NewMainMenu()
case "s":
if len(subscriptions.list.Items()) > 0 {
user := subscriptions.neighbors[subscriptions.list.Index()]
if subscriptions.subscriptions.IsSubscribed(user) {
subscriptions.subscriptions.Unsubscribe(user)
} else {
subscriptions.subscriptions.Subscribe(user)
}
subscriptions.list.SetItem(subscriptions.list.Index(), formatNeighbor(user, subscriptions.subscriptions))
}
case "Enter", "l", "Right":
subscriptions.subscriptions.Write()
ui.ViewChange <- NewUserPage(subscriptions.neighbors[subscriptions.list.Index()].Name)
}
processed = true
}
subscriptions.Draw(state)
return
}
func (subscriptions *Subscriptions) Draw(state *ui.State) {
win := state.Window()
win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: subscriptions.title})
subscriptions.list.Draw(vaxis.Window{
Vx: win.Vx,
Parent: nil,
Column: win.Width/2 - 40,
Row: win.Height/2 - 2,
Width: 80,
Height: 10,
})
if len(subscriptions.list.Items()) == 0 {
win.New(win.Width/2-22, win.Height/2-1, 44, 2).Print(vaxis.Segment{Text: "no subscriptions yet\nvisit your neighbors to subscribe to them!"})
}
win.New(win.Width/2-22, win.Height/2+9, 44, 1).Print(vaxis.Segment{Text: subscriptions.help})
}

View File

@ -171,20 +171,18 @@ func (subscriptions *Subscriptions) IsSubscribed(user User) bool {
func (subscriptions *Subscriptions) Subscribe(user User) {
subscriptions.users = append(subscriptions.users, user.Name)
subscriptions.write()
}
func (subscriptions *Subscriptions) Unsubscribe(user User) {
for i, sub := range subscriptions.users {
if sub == user.Name {
subscriptions.users = append(subscriptions.users[:i], subscriptions.users[i+1:]...)
subscriptions.write()
return
}
}
}
func (subscriptions *Subscriptions) write() {
func (subscriptions *Subscriptions) Write() {
file, err := os.Create(path.Join(os.Getenv("HOME"), ".ttbp/config/subs"))
if err != nil {
return