Skip to content

Commit a7c5ba1

Browse files
authored
fix: make undo message non-blocking (#1455)
## What? Improves queue, by making undo non-blocking ## Why? You had to wait for 5 seconds in order to use Matcha again Signed-off-by: drew <me@andrinoff.com>
1 parent 8710452 commit a7c5ba1

1 file changed

Lines changed: 32 additions & 13 deletions

File tree

main.go

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
tea "charm.land/bubbletea/v2"
3030
"charm.land/lipgloss/v2"
31+
overlay "github.com/floatpane/bubble-overlay"
3132
calendar "github.com/floatpane/go-icalendar"
3233
"github.com/floatpane/matcha/backend"
3334
_ "github.com/floatpane/matcha/backend/imap"
@@ -124,6 +125,7 @@ type mainModel struct {
124125
logCh <-chan logging.Entry
125126
logPanel *tui.LogPanel
126127
pendingJobID string
128+
sendNotice string
127129
}
128130

129131
type logEntryMsg struct {
@@ -1730,11 +1732,13 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { //nolint:gocyclo
17301732
m.service = daemonclient.NewService(m.config)
17311733
}
17321734

1733-
statusText := "Sending email..."
1735+
noticeText := "Sending email..."
17341736
if msg.SignPGP && account != nil && account.PGPKeySource == "yubikey" {
1735-
statusText = "Touch your YubiKey to sign..."
1737+
noticeText = "Touch your YubiKey to sign..."
17361738
}
1737-
m.current = tui.NewStatus(statusText)
1739+
m.sendNotice = noticeText
1740+
m.current = tui.NewChoice()
1741+
m.current, _ = m.current.Update(m.currentWindowSize())
17381742

17391743
// Save contact and delete draft in background
17401744
go func() {
@@ -1764,18 +1768,16 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { //nolint:gocyclo
17641768

17651769
case tui.EmailQueuedMsg:
17661770
m.pendingJobID = msg.JobID
1767-
m.current = tui.NewStatus(fmt.Sprintf("Message sent (%s to undo)", config.Keybinds.Composer.UndoSend))
1768-
return m, tea.Batch(
1769-
m.current.Init(),
1770-
tea.Tick(
1771-
time.Duration(msg.DelaySeconds)*time.Second, func(t time.Time) tea.Msg {
1772-
return tui.EmailDelayExpiredMsg{JobID: msg.JobID}
1773-
}),
1774-
)
1771+
m.sendNotice = fmt.Sprintf("Message sent (%s to undo)", config.Keybinds.Composer.UndoSend)
1772+
return m, tea.Tick(
1773+
time.Duration(msg.DelaySeconds)*time.Second, func(t time.Time) tea.Msg {
1774+
return tui.EmailDelayExpiredMsg{JobID: msg.JobID}
1775+
})
17751776

17761777
case tui.EmailDelayExpiredMsg:
17771778
if m.pendingJobID == msg.JobID {
17781779
m.pendingJobID = ""
1780+
m.sendNotice = ""
17791781
m.previousModel = nil
17801782

17811783
if m.plugins != nil {
@@ -1790,14 +1792,15 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { //nolint:gocyclo
17901792
return m, nil
17911793

17921794
case tui.UndoSendMsg:
1795+
m.sendNotice = ""
17931796
if m.previousModel != nil {
17941797
m.current = m.previousModel
17951798
m.previousModel = nil
17961799
m.current, _ = m.current.Update(m.currentWindowSize())
17971800
return m, m.current.Init()
17981801
}
1799-
1800-
m.previousModel = tui.NewChoice()
1802+
m.current = tui.NewChoice()
1803+
m.current, _ = m.current.Update(m.currentWindowSize())
18011804
return m, m.current.Init()
18021805

18031806
case tui.SendRSVPMsg:
@@ -1832,6 +1835,7 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { //nolint:gocyclo
18321835
})
18331836

18341837
case tui.EmailResultMsg:
1838+
m.sendNotice = ""
18351839
if msg.Err != nil {
18361840
log.Printf("Failed to send email: %v", msg.Err)
18371841
m.previousModel = tui.NewChoice()
@@ -2120,10 +2124,25 @@ func (m *mainModel) View() tea.View {
21202124
if m.showLogPanel {
21212125
v.Content = m.renderWithLogPanel(v.Content)
21222126
}
2127+
if m.sendNotice != "" {
2128+
v.Content = m.renderSendNoticeOverlay(v.Content)
2129+
}
21232130
v.AltScreen = true
21242131
return v
21252132
}
21262133

2134+
func (m *mainModel) renderSendNoticeOverlay(content string) string {
2135+
box := lipgloss.NewStyle().
2136+
Border(lipgloss.RoundedBorder()).
2137+
BorderForeground(theme.ActiveTheme.Accent).
2138+
Padding(0, 1).
2139+
Render(m.sendNotice)
2140+
lines := strings.Split(box, "\n")
2141+
boxWidth := lipgloss.Width(lines[0])
2142+
col := max(0, m.width-boxWidth)
2143+
return overlay.Block(content, lines, 0, col)
2144+
}
2145+
21272146
func (m *mainModel) currentWindowSize() tea.WindowSizeMsg {
21282147
return tea.WindowSizeMsg{
21292148
Width: m.width,

0 commit comments

Comments
 (0)