forked from tildetown/town
skip through applications
parent
327e0551b9
commit
b03e4f069e
|
@ -1,9 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -29,56 +31,79 @@ const (
|
|||
rejectedDir = "/town/signups/rejected"
|
||||
)
|
||||
|
||||
// TODO copypasta from signup cmd
|
||||
type townApplication struct {
|
||||
type townSignup struct {
|
||||
When time.Time
|
||||
Answers map[string]string
|
||||
}
|
||||
|
||||
func (a townApplication) Render() string {
|
||||
// TODO
|
||||
return "TODO"
|
||||
func (a townSignup) Render() string {
|
||||
out := fmt.Sprintf("[-:-:b]submitted:[-:-:-] %s\n", a.When.Format("2006-01-02 15:04"))
|
||||
|
||||
for k, v := range a.Answers {
|
||||
out += fmt.Sprintf("[-:-:b]%s[-:-:-]\n", k)
|
||||
out += strings.TrimSpace(v)
|
||||
out += "\n\n"
|
||||
}
|
||||
|
||||
func getApplications() ([]townApplication, error) {
|
||||
return out
|
||||
}
|
||||
|
||||
func getSignups() ([]townSignup, error) {
|
||||
entries, err := os.ReadDir(signupDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read '%s': %w", signupDir, err)
|
||||
}
|
||||
out := []townApplication{}
|
||||
out := []townSignup{}
|
||||
for _, entry := range entries {
|
||||
if !strings.HasSuffix(entry.Name(), "json") {
|
||||
continue
|
||||
}
|
||||
// TODO read file
|
||||
// TODO unmarshal
|
||||
// TODO append
|
||||
|
||||
abs := path.Join(signupDir, entry.Name())
|
||||
data, err := os.ReadFile(abs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read signup file '%s': %w", abs, err)
|
||||
}
|
||||
|
||||
fmt.Println(string(data))
|
||||
|
||||
var signup townSignup
|
||||
err = json.Unmarshal(data, &signup)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not unmarshal signup file '%s': %w", abs, err)
|
||||
}
|
||||
|
||||
out = append(out, signup)
|
||||
}
|
||||
|
||||
// TODO
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func _main() error {
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
applications, err := getApplications()
|
||||
signups, err := getSignups()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get applications: %w", err)
|
||||
return fmt.Errorf("could not get signups: %w", err)
|
||||
}
|
||||
|
||||
signupIx := 0
|
||||
|
||||
pages := tview.NewPages()
|
||||
mainFlex := tview.NewFlex()
|
||||
|
||||
title := tview.NewTextView()
|
||||
title.SetText(getTitle())
|
||||
title.SetTextAlign(tview.AlignCenter)
|
||||
title.SetTextColor(tcell.ColorPink)
|
||||
title.SetBackgroundColor(tcell.ColorBlack)
|
||||
|
||||
appView := tview.NewTextView()
|
||||
if len(applications) == 0 {
|
||||
appView.SetText("no applications found.")
|
||||
appView.SetDynamicColors(true)
|
||||
if len(signups) == 0 {
|
||||
appView.SetText("no signups found.")
|
||||
} else {
|
||||
appView.SetText(applications[0].Render())
|
||||
appView.SetText(signups[signupIx].Render())
|
||||
}
|
||||
|
||||
legend := tview.NewTextView()
|
||||
|
@ -98,9 +123,14 @@ func _main() error {
|
|||
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch event.Rune() {
|
||||
case 's':
|
||||
// TODO skip
|
||||
signupIx++
|
||||
if signupIx == len(signups) {
|
||||
signupIx = 0
|
||||
}
|
||||
appView.SetText(signups[signupIx].Render())
|
||||
case 'r':
|
||||
// TODO skip to random
|
||||
signupIx = rand.Intn(len(signups))
|
||||
appView.SetText(signups[signupIx].Render())
|
||||
case 'A':
|
||||
// TODO approve
|
||||
case 'R':
|
||||
|
|
Loading…
Reference in New Issue