start work on user management
parent
c71a473d55
commit
f2804c1fc9
|
@ -2,9 +2,12 @@ package app
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
"strconv"
|
||||
|
||||
"git.sr.ht/~rockorager/vaxis"
|
||||
"git.tilde.town/nbsp/neofeels/ttbp"
|
||||
"git.tilde.town/nbsp/neofeels/ui"
|
||||
)
|
||||
|
||||
|
@ -18,14 +21,14 @@ func NewManagement() *Management {
|
|||
return &Management{
|
||||
title,
|
||||
ui.NewList([]string{
|
||||
"read over feels", // TODO
|
||||
"read over feels",
|
||||
"modify feels publishing", // TODO
|
||||
"backup your feels", // TODO
|
||||
"import a feels backup", // TODO
|
||||
"bury some feels", // TODO
|
||||
"delete feels by day", // TODO
|
||||
"purge all feels", // TODO
|
||||
"wipe feels account", // TODO
|
||||
"purge all feels",
|
||||
"wipe feels account",
|
||||
}),
|
||||
"↑↓/kj move ↵ enter q return",
|
||||
}
|
||||
|
@ -51,10 +54,13 @@ func (management *Management) Event(state *ui.State, event vaxis.Event) (process
|
|||
ui.ViewChange <- NewMainMenu()
|
||||
case "Enter", "l", "Right":
|
||||
switch management.list.Index() {
|
||||
case 0:
|
||||
user, _ := user.Current()
|
||||
ui.ViewChange <- NewUserPage(user.Username, true)
|
||||
case 6:
|
||||
management.Confirmation(state, func() {}, "feels purged")
|
||||
management.Confirmation(state, purgeFeels, "feels purged")
|
||||
case 7:
|
||||
management.Confirmation(state, func() {}, "feels account wiped")
|
||||
management.Confirmation(state, wipeAccount, "feels account wiped")
|
||||
}
|
||||
}
|
||||
processed = true
|
||||
|
@ -77,6 +83,19 @@ func (management *Management) Draw(state *ui.State) {
|
|||
win.New(win.Width/2-15, win.Height/2+7, 30, 1).Print(vaxis.Segment{Text: management.help})
|
||||
}
|
||||
|
||||
func purgeFeels() {
|
||||
ttbp.Unpublish()
|
||||
os.RemoveAll(ttbp.PathUserEntries)
|
||||
os.MkdirAll(ttbp.PathUserEntries, 0700)
|
||||
}
|
||||
|
||||
func wipeAccount() {
|
||||
// TODO: edit users.txt
|
||||
ttbp.Unpublish()
|
||||
os.RemoveAll(ttbp.PathUserFeels)
|
||||
close(ui.Quit)
|
||||
}
|
||||
|
||||
// TODO: abstract this to our own List type
|
||||
// TODO: figure out a less janky way instead of nesting event channels
|
||||
func (management *Management) Confirmation(state *ui.State, action func(), message string) {
|
||||
|
|
|
@ -81,7 +81,7 @@ func (neighbors *Neighbors) Event(state *ui.State, event vaxis.Event) (processed
|
|||
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)
|
||||
ui.ViewChange <- NewUserPage(neighbors.neighbors[neighbors.list.Index()].Name, false)
|
||||
}
|
||||
processed = true
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ func (subscriptions *Subscriptions) Event(state *ui.State, event vaxis.Event) (p
|
|||
case "Enter", "l", "Right":
|
||||
if len(subscriptions.list.Items()) > 0 {
|
||||
subscriptions.subscriptions.Write()
|
||||
ui.ViewChange <- NewUserPage(subscriptions.neighbors[subscriptions.list.Index()].Name)
|
||||
ui.ViewChange <- NewUserPage(subscriptions.neighbors[subscriptions.list.Index()].Name, false)
|
||||
}
|
||||
}
|
||||
processed = true
|
||||
|
|
10
app/user.go
10
app/user.go
|
@ -18,9 +18,10 @@ type UserPage struct {
|
|||
list ui.List
|
||||
help string
|
||||
posts []ttbp.Post
|
||||
self bool
|
||||
}
|
||||
|
||||
func NewUserPage(user string) *UserPage {
|
||||
func NewUserPage(user string, self bool) *UserPage {
|
||||
posts := ttbp.GetPostsForUser(user)
|
||||
list := []string{}
|
||||
for _, post := range posts {
|
||||
|
@ -36,6 +37,7 @@ func NewUserPage(user string) *UserPage {
|
|||
ui.NewList(list),
|
||||
"↑↓/kj move ↵ enter q return",
|
||||
posts,
|
||||
self,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +58,11 @@ func (user *UserPage) Event(state *ui.State, event vaxis.Event) (processed bool)
|
|||
i, _ := strconv.Atoi(key.String())
|
||||
user.list.SetIndex(i)
|
||||
case "q", "h", "Left":
|
||||
ui.ViewChange <- NewNeighbors()
|
||||
if user.self {
|
||||
ui.ViewChange <- NewManagement()
|
||||
} else {
|
||||
ui.ViewChange <- NewNeighbors()
|
||||
}
|
||||
case "Enter", "l", "Right":
|
||||
showPost(state, user.posts[user.list.Index()])
|
||||
}
|
||||
|
|
2
main.go
2
main.go
|
@ -36,8 +36,6 @@ press ↵ to set up an account, or Ctrl+c to quit. you can always come back late
|
|||
input := bufio.NewScanner(os.Stdin)
|
||||
input.Scan()
|
||||
|
||||
println(ttbp.PathUserConfig, ttbp.PathUserFeels)
|
||||
|
||||
user, _ := user.Current()
|
||||
header := strings.ReplaceAll(header, "%USER%", user.Username)
|
||||
header = strings.ReplaceAll(header, "%DATETIME%", time.Now().Format(time.DateTime))
|
||||
|
|
11
ttbp/ttbp.go
11
ttbp/ttbp.go
|
@ -296,6 +296,17 @@ func Publish(t time.Time) {
|
|||
// TODO: gopher
|
||||
}
|
||||
|
||||
func Unpublish() {
|
||||
cfg, err := config.Read()
|
||||
if err != nil {
|
||||
return // TODO: expose
|
||||
}
|
||||
if cfg.Publishing {
|
||||
os.RemoveAll(PathUserWWW)
|
||||
os.RemoveAll(path.Join(PathUserHTML, cfg.PublishDir))
|
||||
}
|
||||
}
|
||||
|
||||
func writePage(post Post, header, footer []byte) {
|
||||
dateString := post.Date.Format("20060102.html")
|
||||
file, err := os.Create(path.Join(PathUserWWW, dateString))
|
||||
|
|
Loading…
Reference in New Issue