-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add new input model, use in projects step #30
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
570b0f0
add new text input mmodel
k3llymariee 5bba02a
add new input step to project model, update wizard step to handle tha…
k3llymariee 0e34650
add note about error handling;
k3llymariee 3aaf37e
remove debugging stmt
k3llymariee 7b87371
store projects in memory so we can mimic adding new ones
k3llymariee 3637ba5
refetch projects if we go back to that step from environment step
k3llymariee eb68bff
make fetching resources more generic
k3llymariee 3de5538
add/update comments
k3llymariee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package setup | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/bubbles/textinput" | ||
tea "github.com/charmbracelet/bubbletea" | ||
) | ||
|
||
type inputModel struct { | ||
textInput textinput.Model | ||
done bool | ||
title string | ||
err error | ||
} | ||
|
||
func newTextInputModel(placeholder, title string) inputModel { | ||
ti := textinput.New() | ||
ti.Placeholder = placeholder | ||
ti.Focus() | ||
ti.CharLimit = 156 | ||
ti.Width = 20 | ||
|
||
return inputModel{ | ||
title: title, | ||
textInput: ti, | ||
err: nil, | ||
} | ||
} | ||
|
||
func (m inputModel) Init() tea.Cmd { | ||
return textinput.Blink | ||
} | ||
|
||
func (m inputModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
var cmd tea.Cmd | ||
|
||
switch msg := msg.(type) { | ||
case tea.KeyMsg: | ||
switch msg.Type { | ||
case tea.KeyEnter: | ||
m.done = true | ||
return m, nil | ||
case tea.KeyCtrlC, tea.KeyEsc: | ||
return m, tea.Quit | ||
} | ||
|
||
// TODO: Handle errors | ||
} | ||
|
||
m.textInput, cmd = m.textInput.Update(msg) | ||
return m, cmd | ||
} | ||
|
||
func (m inputModel) View() string { | ||
return fmt.Sprintf( | ||
"%s\n\n%s\n\n%s", | ||
m.title, | ||
m.textInput.View(), | ||
"(esc to quit)", | ||
) + "\n" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ import ( | |
// TODO: we may want to rename this for clarity | ||
type sessionState int | ||
|
||
// generic message type to pass into each models' Update method when we want to perform a new GET request | ||
type fetchResources struct{} | ||
|
||
// list of steps in the wizard | ||
const ( | ||
autoCreateStep sessionState = iota | ||
|
@@ -82,28 +85,24 @@ func (m WizardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | |
m.currFlagKey = "setup-wizard-flag" | ||
m.currStep = flagsStep + 1 | ||
} else { | ||
projModel, _ := m.steps[projectsStep].Update(fetchProjects{}) | ||
// we need to cast this to get the data out of it, but maybe we can create our own interface with | ||
// common values such as Choice() and Err() so we don't have to cast | ||
p, ok := projModel.(projectModel) | ||
if ok { | ||
if p.err != nil { | ||
m.err = p.err | ||
return m, nil | ||
} | ||
} | ||
// update projModel with the fetched projects | ||
m.steps[projectsStep] = projModel | ||
// go to the next step | ||
// pre-load projects | ||
m.steps[projectsStep], _ = m.steps[projectsStep].Update(fetchResources{}) | ||
m.currStep += 1 | ||
} | ||
} | ||
case projectsStep: | ||
projModel, _ := m.steps[projectsStep].Update(msg) | ||
// we need to cast this to get the data out of it, but maybe we can create our own interface with | ||
// common values such as Choice() and Err() so we don't have to cast | ||
Comment on lines
+95
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but we do need to do it here so i moved that comment down |
||
p, ok := projModel.(projectModel) | ||
if ok { | ||
m.currProjectKey = p.choice | ||
m.currStep += 1 | ||
// update projModel with new input model | ||
m.steps[projectsStep] = p | ||
// only progress if we don't want to show input | ||
if !p.showInput { | ||
m.currStep += 1 | ||
} | ||
} | ||
case environmentsStep: | ||
envModel, _ := m.steps[environmentsStep].Update(msg) | ||
|
@@ -137,6 +136,8 @@ func (m WizardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | |
} | ||
// only go back if not on the first step | ||
if m.currStep > autoCreateStep { | ||
// fetch resources for the previous step again in case we created new ones | ||
m.steps[m.currStep-1], _ = m.steps[m.currStep-1].Update(fetchResources{}) | ||
m.currStep -= 1 | ||
} | ||
case key.Matches(msg, keys.Quit): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think we actually needed to do this casting here