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