2023-02-14 04:48:12 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-02-14 07:33:53 +00:00
|
|
|
"math/rand"
|
2023-02-14 04:48:12 +00:00
|
|
|
"os"
|
2023-02-14 07:33:53 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
|
|
"github.com/rivo/tview"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getTitle() string {
|
|
|
|
titles := []string{
|
|
|
|
"yo bum rush the show",
|
|
|
|
"can i kick it?",
|
|
|
|
"super nintendo sega genesis",
|
|
|
|
"birthdays was the worst days",
|
|
|
|
"where were you when we were getting high?",
|
|
|
|
"it's real time, real time, time to get real",
|
|
|
|
}
|
|
|
|
return titles[rand.Intn(len(titles))]
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
signupDir = "/town/signups"
|
|
|
|
acceptedDir = "/town/signups/accepted"
|
|
|
|
rejectedDir = "/town/signups/rejected"
|
2023-02-14 04:48:12 +00:00
|
|
|
)
|
|
|
|
|
2023-02-14 07:33:53 +00:00
|
|
|
// TODO copypasta from signup cmd
|
|
|
|
type townApplication struct {
|
|
|
|
When time.Time
|
|
|
|
Answers map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a townApplication) Render() string {
|
|
|
|
// TODO
|
|
|
|
return "TODO"
|
|
|
|
}
|
|
|
|
|
|
|
|
func getApplications() ([]townApplication, error) {
|
|
|
|
entries, err := os.ReadDir(signupDir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to read '%s': %w", signupDir, err)
|
|
|
|
}
|
|
|
|
out := []townApplication{}
|
|
|
|
for _, entry := range entries {
|
|
|
|
if !strings.HasSuffix(entry.Name(), "json") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// TODO read file
|
|
|
|
// TODO unmarshal
|
|
|
|
// TODO append
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
2023-02-14 04:48:12 +00:00
|
|
|
func _main() error {
|
2023-02-14 07:33:53 +00:00
|
|
|
rand.Seed(time.Now().Unix())
|
|
|
|
|
|
|
|
applications, err := getApplications()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("could not get applications: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
pages := tview.NewPages()
|
|
|
|
mainFlex := tview.NewFlex()
|
|
|
|
|
|
|
|
title := tview.NewTextView()
|
|
|
|
title.SetText(getTitle())
|
|
|
|
|
|
|
|
appView := tview.NewTextView()
|
|
|
|
if len(applications) == 0 {
|
|
|
|
appView.SetText("no applications found.")
|
|
|
|
} else {
|
|
|
|
appView.SetText(applications[0].Render())
|
|
|
|
}
|
|
|
|
|
|
|
|
legend := tview.NewTextView()
|
|
|
|
legend.SetText("TODO actions legend")
|
|
|
|
|
|
|
|
mainFlex.SetDirection(tview.FlexRow)
|
|
|
|
mainFlex.AddItem(title, 1, -1, false)
|
|
|
|
mainFlex.AddItem(appView, 0, 1, true)
|
|
|
|
mainFlex.AddItem(legend, 1, -1, false)
|
|
|
|
|
|
|
|
pages.AddPage("main", mainFlex, true, true)
|
|
|
|
// TODO page for textarea to notate
|
|
|
|
|
|
|
|
app := tview.NewApplication()
|
|
|
|
app.SetRoot(pages, true)
|
|
|
|
|
|
|
|
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
|
|
|
switch event.Rune() {
|
|
|
|
case 's':
|
|
|
|
// TODO skip
|
|
|
|
case 'r':
|
|
|
|
// TODO skip to random
|
|
|
|
case 'A':
|
|
|
|
// TODO approve
|
|
|
|
case 'R':
|
|
|
|
// TODO reject
|
|
|
|
case 'n':
|
|
|
|
// TODO notate
|
|
|
|
case 'Q':
|
|
|
|
app.Stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
return event
|
|
|
|
})
|
|
|
|
|
|
|
|
return app.Run()
|
2023-02-14 04:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
err := _main()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|