~edwargix/tallyard

cf6b24c5025b391b7c4e08af8ef7a071900beb2b — David Florness 4 years ago a87dc50
Don't create election if CreateElectionTUI form wasn't completed
1 files changed, 9 insertions(+), 0 deletions(-)

M ui/tui.go
M ui/tui.go => ui/tui.go +9 -0
@@ 128,6 128,9 @@ func RoomTUI(client *mautrix.Client, roomID id.RoomID, elections *election.Elect

		// user wants to create election (i == 0)
		title, candidates := CreateElectionTUI()
		if candidates == nil {
			return
		}
		log.Debugf("title: %s", title)
		log.Debugf("candidates: %s", candidates)
		var err error


@@ 197,9 200,11 @@ func CreateElectionTUI() (title string, candidates []election.Candidate) {
			n--
		}
	}
	hitSubmit := false
	done := func() {
		// TODO: ensure none of the candidates are empty
		app.Stop()
		hitSubmit = true
		title = form.GetFormItem(0).(*tview.InputField).GetText()
		for i := 1; i <= n; i++ {
			candidates = append(candidates,


@@ 216,6 221,10 @@ func CreateElectionTUI() (title string, candidates []election.Candidate) {
	if err := app.SetRoot(form, true).SetFocus(form).Run(); err != nil {
		panic(err)
	}
	if !hitSubmit {
		// user didn't hit submit button; consider form incomplete
		return "", nil
	}
	return title, candidates
}