Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions pkg/ui/dashboard/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ConfirmModel struct {
keys KeyMap
confirmed bool
canceled bool
deleting bool
}

// NewConfirm creates a new confirmation dialog.
Expand Down Expand Up @@ -46,16 +47,34 @@ func (m ConfirmModel) IsCanceled() bool {

// IsDone returns true if the dialog is complete.
func (m ConfirmModel) IsDone() bool {
if m.deleting {
return false
}
return m.confirmed || m.canceled
}

// SetDeleting sets the deleting state.
func (m ConfirmModel) SetDeleting(deleting bool) ConfirmModel {
m.deleting = deleting
return m
}

// IsDeleting returns true if a deletion is in progress.
func (m ConfirmModel) IsDeleting() bool {
return m.deleting
}

// Init initializes the component.
func (m ConfirmModel) Init() tea.Cmd {
return nil
}

// Update handles messages.
func (m ConfirmModel) Update(msg tea.Msg) (ConfirmModel, tea.Cmd) {
if m.deleting {
return m, nil
}

if keyMsg, ok := msg.(tea.KeyMsg); ok {
switch {
case key.Matches(keyMsg, m.keys.Confirm):
Expand Down Expand Up @@ -84,6 +103,32 @@ func (m ConfirmModel) View() string {
Bold(true).
Foreground(warningColor)

if m.deleting {
b.WriteString(titleStyle.Render("Deleting Workspace"))
b.WriteString("\n\n")
b.WriteString("Deleting workspace and cleaning up branches...")
b.WriteString("\n\n")
if m.action.Workspace != "" {
fmt.Fprintf(&b, "Workspace: %s\n", m.action.Workspace)
}
b.WriteString("\n")
b.WriteString("Please wait...")

content := boxStyle.Render(b.String())

if m.width > 0 && m.height > 0 {
return lipgloss.Place(
m.width,
m.height,
lipgloss.Center,
lipgloss.Center,
content,
)
}

return content
}

descStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color("252")).
MarginTop(1).
Expand All @@ -100,10 +145,10 @@ func (m ConfirmModel) View() string {
b.WriteString("\n\n")

if m.action.Workspace != "" {
b.WriteString(fmt.Sprintf("Workspace: %s\n", m.action.Workspace))
fmt.Fprintf(&b, "Workspace: %s\n", m.action.Workspace)
}
if m.action.Repo != "" {
b.WriteString(fmt.Sprintf("Repository: %s\n", m.action.Repo))
fmt.Fprintf(&b, "Repository: %s\n", m.action.Repo)
}

b.WriteString("\n")
Expand Down
13 changes: 9 additions & 4 deletions pkg/ui/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ func (m DashboardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.showConfirm {
var cmd tea.Cmd
m.confirmModel, cmd = m.confirmModel.Update(msg)
if m.confirmModel.IsDone() {
if m.confirmModel.IsConfirmed() {
cmd = m.executeConfirmedAction()
}
if m.confirmModel.IsConfirmed() && !m.confirmModel.IsDeleting() {
m.confirmModel = m.confirmModel.SetDeleting(true)
cmd = m.executeConfirmedAction()
return m, cmd
}
if m.confirmModel.IsCanceled() {
m.showConfirm = false
}
return m, cmd
Expand Down Expand Up @@ -261,6 +263,9 @@ func (m DashboardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil

case ActionCompleteMsg:
if msg.Action == ActionDelete {
m.showConfirm = false
}
switch {
case msg.Output != "":
m.statusMessage = msg.Output
Expand Down