From 1c2df98d7d7df950f5d3056b4fcc614c3ad313e5 Mon Sep 17 00:00:00 2001 From: Hamid Raza Date: Wed, 12 Apr 2023 16:52:45 +0530 Subject: [PATCH] feat: toggle form issue --- configuration/components/Footer.go | 23 ++++++++++++++++++----- configuration/configuration.go | 4 ++-- configuration/pages/Categories.go | 19 ++----------------- configuration/pages/ConfigurationForm.go | 18 +++--------------- ui/go.mod | 4 ++-- ui/go.sum | 4 ++++ ui/ui.go | 2 +- wizard/wizard.go | 4 ++-- 8 files changed, 34 insertions(+), 44 deletions(-) diff --git a/configuration/components/Footer.go b/configuration/components/Footer.go index 1948db3..112c44b 100644 --- a/configuration/components/Footer.go +++ b/configuration/components/Footer.go @@ -4,6 +4,7 @@ import ( "github.com/gdamore/tcell/v2" "github.com/rivo/tview" "github.com/stader-labs/ethcli-ui/configuration/config" + "github.com/stader-labs/ethcli-ui/configuration/state" ) func emptyText() tview.Primitive { @@ -15,7 +16,7 @@ func emptyText() tview.Primitive { SetTextStyle(textStyle) } -func Footer(pageName string, onGoBack, onQuit, onSaveExit, onOpenConfig func()) tview.Primitive { +func Footer(pageName string, app *tview.Application, onGoBack func()) tview.Primitive { textStyle := tcell.StyleDefault.Background(tcell.ColorDarkSlateGray). Foreground(tcell.ColorAntiqueWhite) @@ -57,8 +58,12 @@ func Footer(pageName string, onGoBack, onQuit, onSaveExit, onOpenConfig func()) { txt := "Ctrl+C: Quit without Saving" btn := tview.NewButton(txt).SetStyle(textStyle).SetDisabledStyle(textStyle) - if onQuit != nil { - btn.SetStyle(textStyle.Underline(true)).SetSelectedFunc(onQuit) + if pageName != config.PageID.Categories { + btn.SetStyle(textStyle.Underline(true)).SetSelectedFunc(func() { + state.OpenWizard = false + state.Saved = false + app.Stop() + }) } else { btn.SetDisabled(true) } @@ -82,10 +87,18 @@ func Footer(pageName string, onGoBack, onQuit, onSaveExit, onOpenConfig func()) saveNExitBtn := tview.NewButton("Save and Exit"). SetStyle(btnStyle). - SetSelectedFunc(onSaveExit) + SetSelectedFunc(func() { + state.OpenWizard = false + state.Saved = true + app.Stop() + }) openConfig := tview.NewButton("Open the Configuration Manager"). SetStyle(btnStyle). - SetSelectedFunc(onOpenConfig) + SetSelectedFunc(func() { + state.OpenWizard = true + state.Saved = false + app.Stop() + }) footerTopRow := tview.NewFlex(). SetDirection(tview.FlexColumn). diff --git a/configuration/configuration.go b/configuration/configuration.go index 54ec3f2..5d7b3d5 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -19,11 +19,11 @@ func Run(settings *map[string]interface{}) ( configurations *map[string]interface{}, ) { app := tview.NewApplication().EnableMouse(true) - state.Saved = false - state.OpenWizard = false if settings != nil { state.Configuration = *settings + state.Saved = false + state.OpenWizard = false } pages.Setup(app) diff --git a/configuration/pages/Categories.go b/configuration/pages/Categories.go index 2fd1304..a1d1412 100644 --- a/configuration/pages/Categories.go +++ b/configuration/pages/Categories.go @@ -57,23 +57,8 @@ func (p *Categories) Page() tview.Primitive { AddItem(components.Header("Configuration Summary"), 3, 1, false). AddItem(body, 0, 1, false). AddItem( - components.Footer( - config.PageID.Categories, - nil, - func() { - p.App.Stop() - }, - func() { - state.Saved = true - state.OpenWizard = false - p.App.Stop() - }, - func() { - state.Saved = false - state.OpenWizard = true - p.App.Stop() - }, - ), 5, 1, false, + components.Footer(config.PageID.Categories, p.App, nil), + 5, 1, false, ) p.updateDescription() diff --git a/configuration/pages/ConfigurationForm.go b/configuration/pages/ConfigurationForm.go index bb8ea26..3db6bc2 100644 --- a/configuration/pages/ConfigurationForm.go +++ b/configuration/pages/ConfigurationForm.go @@ -46,21 +46,9 @@ func (p *ConfigurationForm) Page() tview.Primitive { AddItem(p.header, 3, 1, false). AddItem(body, 0, 1, false). AddItem( - components.Footer( - config.PageID.ConfigurationForm, - p.GoBack, - func() { - p.App.Stop() - }, - func() { - state.Saved = true - p.App.Stop() - }, - func() { - state.OpenWizard = false - p.App.Stop() - }, - ), 5, 1, false) + components.Footer(config.PageID.ConfigurationForm, p.App, p.GoBack), + 5, 1, false, + ) return root } diff --git a/ui/go.mod b/ui/go.mod index 0ddce5c..462169f 100644 --- a/ui/go.mod +++ b/ui/go.mod @@ -3,8 +3,8 @@ module github.com/stader-labs/ethcli-ui/ui go 1.19 require ( - github.com/stader-labs/ethcli-ui/configuration v0.0.0-20230412083342-9409f8319e0f - github.com/stader-labs/ethcli-ui/wizard v0.0.0-20230412084952-460dc9bbbcdf + github.com/stader-labs/ethcli-ui/configuration v0.0.0-20230412104132-f4eecaffdded + github.com/stader-labs/ethcli-ui/wizard v0.0.0-20230412104132-f4eecaffdded ) require ( diff --git a/ui/go.sum b/ui/go.sum index 08d1a77..cad5ca4 100644 --- a/ui/go.sum +++ b/ui/go.sum @@ -20,8 +20,12 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/stader-labs/ethcli-ui/configuration v0.0.0-20230412083342-9409f8319e0f h1:FrlmhvAJuNzSM6+rPsFk03UNqW4y/743FFxjPzSKvgk= github.com/stader-labs/ethcli-ui/configuration v0.0.0-20230412083342-9409f8319e0f/go.mod h1:1aWp76l573sAUYRVwu6nXnL9cSkU2PDdZmLZw7mZ+4U= +github.com/stader-labs/ethcli-ui/configuration v0.0.0-20230412104132-f4eecaffdded h1:ksvp8iiGrgpVSC5Z/dCjfcXJvWI7s4PEvmGOf8XhxPY= +github.com/stader-labs/ethcli-ui/configuration v0.0.0-20230412104132-f4eecaffdded/go.mod h1:1aWp76l573sAUYRVwu6nXnL9cSkU2PDdZmLZw7mZ+4U= github.com/stader-labs/ethcli-ui/wizard v0.0.0-20230412084952-460dc9bbbcdf h1:HBraEy+bYECMsXbRs6FtFnVMS409oIUSWh3rc3lEd/c= github.com/stader-labs/ethcli-ui/wizard v0.0.0-20230412084952-460dc9bbbcdf/go.mod h1:hsVgdTJijflYAKGDE8Io692K28QVyjh68JT45jrCD1M= +github.com/stader-labs/ethcli-ui/wizard v0.0.0-20230412104132-f4eecaffdded h1:6Oxw8WKTf0+IsiF0NvBz3NilVVTPY4DmRWVE+BJcaXA= +github.com/stader-labs/ethcli-ui/wizard v0.0.0-20230412104132-f4eecaffdded/go.mod h1:hsVgdTJijflYAKGDE8Io692K28QVyjh68JT45jrCD1M= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= diff --git a/ui/ui.go b/ui/ui.go index 45254a8..0fbe583 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -45,5 +45,5 @@ func Run( wizardSettings *wpages.SettingsType, configurationSettings *map[string]interface{}, ) { - return handleUI("configuration", wSettings, cSettings) + return handleUI("wizard", wSettings, cSettings) } diff --git a/wizard/wizard.go b/wizard/wizard.go index fe89603..39b6f81 100644 --- a/wizard/wizard.go +++ b/wizard/wizard.go @@ -26,11 +26,11 @@ func Run(s *pages.SettingsType) ( ) { state.CurrentApp = tview.NewApplication().EnableMouse(true) startPageID := config.PageID.Network - state.Confirmed = false - state.OpenConfigurationUI = false if s != nil { pages.SetSettings(*s) + state.Confirmed = false + state.OpenConfigurationUI = false } smallScreenAlert := components.Alert(