basic email validation

the code for the panes is getting messy. since we have one window we
constantly reuse, and especially now that we have weird state-dependent
validation. probably good to rework?
trunk
equa 2023-07-11 22:08:22 -04:00
parent a124b27021
commit 0472c24199
1 changed files with 25 additions and 8 deletions

View File

@ -136,7 +136,7 @@ func _main() error {
appView.SetDynamicColors(true)
legend := tview.NewTextView()
legend.SetText("s: skip r: random A: approve R: reject N: notate Q: quit")
legend.SetText("s/S: next/prev r: random A: approve R: reject N: notate Q: quit")
legend.SetTextColor(tcell.ColorPurple)
legend.SetTextAlign(tview.AlignCenter)
legend.SetBackgroundColor(tcell.ColorBlack)
@ -172,7 +172,7 @@ func _main() error {
mainFlex.AddItem(bottomFlex, 1, -1, false)
// set scrollable
mainFlex.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
appView.InputHandler()(event, func (p tview.Primitive) {})
appView.InputHandler()(event, func(p tview.Primitive) {})
return nil
})
@ -231,21 +231,18 @@ func _main() error {
decisionFI.SetOptions([]string{"accepted", "rejected"}, func(_ string, _ int) {})
cleanEmailInput := tview.NewInputField()
cleanEmailInput.SetLabel("clean email")
cleanEmailInput.SetLabel("clean email ")
cleanEmailInput.SetAcceptanceFunc(func(tx string, _ rune) bool { return len(tx) > 0 })
reviewForm.AddFormItem(decisionFI)
reviewForm.AddFormItem(cleanEmailInput)
reviewForm.AddButton("submit", func() {
currSignup := signups[signupIx]
cleanEmail := reviewForm.GetFormItemByLabel("clean email").(*tview.InputField).GetText()
defer func() {
cleanEmailInput.SetText("")
}()
cleanEmail := cleanEmailInput.GetText()
currSignup.CleanEmail = cleanEmail
decision := models.SignupRejected
_, d := reviewForm.GetFormItemByLabel("decision").(*tview.DropDown).GetCurrentOption()
_, d := decisionFI.GetCurrentOption()
if d == "accepted" {
decision = models.SignupAccepted
}
@ -332,12 +329,16 @@ func _main() error {
updateCount()
render()
}
// TODO: there's a bunch of messy state management.
// should we generate this pane functionally?
case 'A':
if len(signups) == 0 {
return nil
}
emailVal := signups[signupIx].Email
providedEmailView.SetText(emailVal)
cleanEmailInput.SetLabel("clean email ")
cleanEmailInput.SetText("")
/*
TODO the placeholder doesn't appear to become the default text which is
what I wanted it to do. Just taking this out so the blank box beckons
@ -346,6 +347,13 @@ func _main() error {
cleanEmailInput.SetPlaceholder(
strings.TrimSpace(strings.ReplaceAll(emailVal, "\n", " ")))
*/
cleanEmailInput.SetChangedFunc(func(text string) {
if strings.Contains(emailVal, text) {
cleanEmailInput.SetLabel("clean email ")
} else {
cleanEmailInput.SetLabel("[red]clean email :(")
}
})
decisionFI.SetCurrentOption(0)
pages.SwitchToPage("review")
app.SetFocus(cleanEmailInput)
@ -356,6 +364,8 @@ func _main() error {
}
emailVal := signups[signupIx].Email
providedEmailView.SetText(emailVal)
cleanEmailInput.SetLabel("clean email ")
cleanEmailInput.SetText("")
/*
TODO the placeholder doesn't appear to become the default text which is
what I wanted it to do. Just taking this out so the blank box beckons
@ -364,6 +374,13 @@ func _main() error {
cleanEmailInput.SetPlaceholder(
strings.TrimSpace(strings.ReplaceAll(emailVal, "\n", " ")))
*/
cleanEmailInput.SetChangedFunc(func(text string) {
if strings.Contains(emailVal, text) {
cleanEmailInput.SetLabel("clean email ")
} else {
cleanEmailInput.SetLabel("[red]clean email :(")
}
})
decisionFI.SetCurrentOption(1)
pages.SwitchToPage("review")
app.SetFocus(cleanEmailInput)