fix: add send button

This commit is contained in:
Maas Lalani 2023-06-15 14:38:57 -04:00
parent 3412cb20d2
commit 6646e0c54e
No known key found for this signature in database
GPG key ID: 5A6ED5CBF1A0A000
3 changed files with 25 additions and 4 deletions

View file

@ -28,7 +28,7 @@ func DefaultKeybinds() KeyMap {
key.WithDisabled(),
),
Attach: key.NewBinding(
key.WithKeys("a"),
key.WithKeys("a", "enter"),
key.WithHelp("a", "attach file"),
key.WithDisabled(),
),
@ -67,8 +67,11 @@ func (k KeyMap) FullHelp() [][]key.Binding {
func (m *Model) updateKeymap() {
m.keymap.Attach.SetEnabled(m.state == editingAttachments)
canSend := m.From.Value() != "" && m.To.Value() != "" && m.Subject.Value() != "" && m.Body.Value() != ""
m.keymap.Send.SetEnabled(canSend && m.state != editingBody && m.state != pickingFile)
m.keymap.Send.SetEnabled(m.canSend() && m.state == hoveringSendButton)
m.keymap.Unattach.SetEnabled(m.state == editingAttachments && len(m.Attachments.Items()) > 0)
m.keymap.Back.SetEnabled(m.state == pickingFile)
}
func (m Model) canSend() bool {
return m.From.Value() != "" && m.To.Value() != "" && m.Subject.Value() != "" && m.Body.Value() != ""
}

View file

@ -25,6 +25,7 @@ const (
editingSubject
editingBody
editingAttachments
hoveringSendButton
pickingFile
sendingEmail
)
@ -193,6 +194,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case editingBody:
m.state = editingAttachments
case editingAttachments:
m.state = hoveringSendButton
case hoveringSendButton:
m.state = editingFrom
}
m.focusActiveInput()
@ -201,7 +204,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.blurInputs()
switch m.state {
case editingFrom:
m.state = editingAttachments
m.state = hoveringSendButton
case editingTo:
m.state = editingFrom
case editingSubject:
@ -210,6 +213,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.state = editingSubject
case editingAttachments:
m.state = editingBody
case hoveringSendButton:
m.state = editingAttachments
}
m.focusActiveInput()
@ -339,6 +344,14 @@ func (m Model) View() string {
s.WriteString("\n\n")
s.WriteString(m.Attachments.View())
s.WriteString("\n")
if m.state == hoveringSendButton && m.canSend() {
s.WriteString(sendButtonActiveStyle.Render("Send"))
} else if m.state == hoveringSendButton {
s.WriteString(sendButtonInactiveStyle.Render("Send"))
} else {
s.WriteString(sendButtonStyle.Render("Send"))
}
s.WriteString("\n\n")
s.WriteString(m.help.View(m.keymap))
if m.err != nil {

View file

@ -8,6 +8,7 @@ import (
)
const accentColor = lipgloss.Color("99")
const yellowColor = lipgloss.Color("#ECFD66")
const whiteColor = lipgloss.Color("255")
const grayColor = lipgloss.Color("241")
const darkGrayColor = lipgloss.Color("236")
@ -29,6 +30,10 @@ var (
errorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#FF5F87"))
commentStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#757575"))
sendButtonActiveStyle = lipgloss.NewStyle().Background(accentColor).Foreground(yellowColor).Padding(0, 2)
sendButtonInactiveStyle = lipgloss.NewStyle().Background(darkGrayColor).Foreground(lightGrayColor).Padding(0, 2)
sendButtonStyle = lipgloss.NewStyle().Background(darkGrayColor).Foreground(grayColor).Padding(0, 2)
inlineCodeStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#FF5F87")).Background(lipgloss.Color("#3A3A3A")).Padding(0, 1)
linkStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#00AF87")).Underline(true)
)