mirror of
https://github.com/ivabus/pop
synced 2024-11-10 02:25:19 +03:00
fix: add send button
This commit is contained in:
parent
3412cb20d2
commit
6646e0c54e
|
@ -28,7 +28,7 @@ func DefaultKeybinds() KeyMap {
|
||||||
key.WithDisabled(),
|
key.WithDisabled(),
|
||||||
),
|
),
|
||||||
Attach: key.NewBinding(
|
Attach: key.NewBinding(
|
||||||
key.WithKeys("a"),
|
key.WithKeys("a", "enter"),
|
||||||
key.WithHelp("a", "attach file"),
|
key.WithHelp("a", "attach file"),
|
||||||
key.WithDisabled(),
|
key.WithDisabled(),
|
||||||
),
|
),
|
||||||
|
@ -67,8 +67,11 @@ func (k KeyMap) FullHelp() [][]key.Binding {
|
||||||
|
|
||||||
func (m *Model) updateKeymap() {
|
func (m *Model) updateKeymap() {
|
||||||
m.keymap.Attach.SetEnabled(m.state == editingAttachments)
|
m.keymap.Attach.SetEnabled(m.state == editingAttachments)
|
||||||
canSend := m.From.Value() != "" && m.To.Value() != "" && m.Subject.Value() != "" && m.Body.Value() != ""
|
m.keymap.Send.SetEnabled(m.canSend() && m.state == hoveringSendButton)
|
||||||
m.keymap.Send.SetEnabled(canSend && m.state != editingBody && m.state != pickingFile)
|
|
||||||
m.keymap.Unattach.SetEnabled(m.state == editingAttachments && len(m.Attachments.Items()) > 0)
|
m.keymap.Unattach.SetEnabled(m.state == editingAttachments && len(m.Attachments.Items()) > 0)
|
||||||
m.keymap.Back.SetEnabled(m.state == pickingFile)
|
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() != ""
|
||||||
|
}
|
||||||
|
|
15
model.go
15
model.go
|
@ -25,6 +25,7 @@ const (
|
||||||
editingSubject
|
editingSubject
|
||||||
editingBody
|
editingBody
|
||||||
editingAttachments
|
editingAttachments
|
||||||
|
hoveringSendButton
|
||||||
pickingFile
|
pickingFile
|
||||||
sendingEmail
|
sendingEmail
|
||||||
)
|
)
|
||||||
|
@ -193,6 +194,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
case editingBody:
|
case editingBody:
|
||||||
m.state = editingAttachments
|
m.state = editingAttachments
|
||||||
case editingAttachments:
|
case editingAttachments:
|
||||||
|
m.state = hoveringSendButton
|
||||||
|
case hoveringSendButton:
|
||||||
m.state = editingFrom
|
m.state = editingFrom
|
||||||
}
|
}
|
||||||
m.focusActiveInput()
|
m.focusActiveInput()
|
||||||
|
@ -201,7 +204,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
m.blurInputs()
|
m.blurInputs()
|
||||||
switch m.state {
|
switch m.state {
|
||||||
case editingFrom:
|
case editingFrom:
|
||||||
m.state = editingAttachments
|
m.state = hoveringSendButton
|
||||||
case editingTo:
|
case editingTo:
|
||||||
m.state = editingFrom
|
m.state = editingFrom
|
||||||
case editingSubject:
|
case editingSubject:
|
||||||
|
@ -210,6 +213,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
m.state = editingSubject
|
m.state = editingSubject
|
||||||
case editingAttachments:
|
case editingAttachments:
|
||||||
m.state = editingBody
|
m.state = editingBody
|
||||||
|
case hoveringSendButton:
|
||||||
|
m.state = editingAttachments
|
||||||
}
|
}
|
||||||
m.focusActiveInput()
|
m.focusActiveInput()
|
||||||
|
|
||||||
|
@ -339,6 +344,14 @@ func (m Model) View() string {
|
||||||
s.WriteString("\n\n")
|
s.WriteString("\n\n")
|
||||||
s.WriteString(m.Attachments.View())
|
s.WriteString(m.Attachments.View())
|
||||||
s.WriteString("\n")
|
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))
|
s.WriteString(m.help.View(m.keymap))
|
||||||
|
|
||||||
if m.err != nil {
|
if m.err != nil {
|
||||||
|
|
5
style.go
5
style.go
|
@ -8,6 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const accentColor = lipgloss.Color("99")
|
const accentColor = lipgloss.Color("99")
|
||||||
|
const yellowColor = lipgloss.Color("#ECFD66")
|
||||||
const whiteColor = lipgloss.Color("255")
|
const whiteColor = lipgloss.Color("255")
|
||||||
const grayColor = lipgloss.Color("241")
|
const grayColor = lipgloss.Color("241")
|
||||||
const darkGrayColor = lipgloss.Color("236")
|
const darkGrayColor = lipgloss.Color("236")
|
||||||
|
@ -29,6 +30,10 @@ var (
|
||||||
errorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#FF5F87"))
|
errorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#FF5F87"))
|
||||||
commentStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#757575"))
|
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)
|
inlineCodeStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#FF5F87")).Background(lipgloss.Color("#3A3A3A")).Padding(0, 1)
|
||||||
linkStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#00AF87")).Underline(true)
|
linkStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#00AF87")).Underline(true)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue