Skip to content

Commit

Permalink
feat: toggle form issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidraza committed Apr 12, 2023
1 parent f4eecaf commit 1c2df98
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 44 deletions.
23 changes: 18 additions & 5 deletions configuration/components/Footer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 2 additions & 17 deletions configuration/pages/Categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 3 additions & 15 deletions configuration/pages/ConfigurationForm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions ui/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions ui/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ func Run(
wizardSettings *wpages.SettingsType,
configurationSettings *map[string]interface{},
) {
return handleUI("configuration", wSettings, cSettings)
return handleUI("wizard", wSettings, cSettings)
}
4 changes: 2 additions & 2 deletions wizard/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1c2df98

Please sign in to comment.