Fix q key behavior in client details view
This commit is contained in:
@@ -29,6 +29,10 @@ var (
|
||||
addHelpStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("241")).
|
||||
MarginTop(1)
|
||||
loadingStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("62")).
|
||||
Bold(true).
|
||||
MarginTop(1)
|
||||
)
|
||||
|
||||
// NewAddScreen creates a new add screen
|
||||
@@ -71,14 +75,24 @@ func NewAddScreen() *AddScreen {
|
||||
),
|
||||
)
|
||||
|
||||
// Create spinner for loading states
|
||||
s := spinner.New()
|
||||
s.Spinner = spinner.Dot
|
||||
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("62"))
|
||||
|
||||
return &AddScreen{
|
||||
form: form,
|
||||
quitting: false,
|
||||
form: form,
|
||||
quitting: false,
|
||||
spinner: s,
|
||||
isCreating: false,
|
||||
}
|
||||
}
|
||||
|
||||
// Init initializes the add screen
|
||||
func (s *AddScreen) Init() tea.Cmd {
|
||||
if s.isCreating {
|
||||
return s.spinner.Tick
|
||||
}
|
||||
return s.form.Init()
|
||||
}
|
||||
|
||||
@@ -90,11 +104,20 @@ func (s *AddScreen) Update(msg tea.Msg) (Screen, tea.Cmd) {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "q", "ctrl+c", "esc":
|
||||
// Cancel and return to list
|
||||
return nil, nil
|
||||
// Cancel and return to list (only if not creating)
|
||||
if !s.isCreating {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If creating, update spinner instead of form
|
||||
if s.isCreating {
|
||||
var cmd tea.Cmd
|
||||
s.spinner, cmd = s.spinner.Update(msg)
|
||||
return s, cmd
|
||||
}
|
||||
|
||||
// Update the form
|
||||
form, cmd := s.form.Update(msg)
|
||||
if f, ok := form.(*huh.Form); ok {
|
||||
@@ -108,6 +131,8 @@ func (s *AddScreen) Update(msg tea.Msg) (Screen, tea.Cmd) {
|
||||
dns := s.form.GetString("dns")
|
||||
usePSK := s.form.GetBool("use_psk")
|
||||
|
||||
// Set creating state and start spinner
|
||||
s.isCreating = true
|
||||
// Create the client
|
||||
return s, s.createClient(name, dns, usePSK)
|
||||
}
|
||||
@@ -121,6 +146,16 @@ func (s *AddScreen) View() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
if s.isCreating {
|
||||
return loadingStyle.Render(
|
||||
lipgloss.JoinVertical(
|
||||
lipgloss.Left,
|
||||
addTitleStyle.Render("Add New WireGuard Client"),
|
||||
s.spinner.View()+" Creating client configuration, please wait...",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
content := lipgloss.JoinVertical(
|
||||
lipgloss.Left,
|
||||
addTitleStyle.Render("Add New WireGuard Client"),
|
||||
|
||||
Reference in New Issue
Block a user