fix: bad ux
This commit is contained in:
parent
a70ed5a372
commit
5a425b8c60
15 changed files with 791 additions and 463 deletions
93
internal/ui/pages/domainmenu/model.go
Normal file
93
internal/ui/pages/domainmenu/model.go
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
package domainmenu
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.juancwu.dev/juancwu/porkbacon/internal/porkbun"
|
||||
"git.juancwu.dev/juancwu/porkbacon/internal/ui/messages"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type menuItem struct {
|
||||
title, desc string
|
||||
id string
|
||||
}
|
||||
|
||||
func (i menuItem) Title() string { return i.title }
|
||||
func (i menuItem) Description() string { return i.desc }
|
||||
func (i menuItem) FilterValue() string { return i.title }
|
||||
|
||||
const (
|
||||
actionDetails = "details"
|
||||
actionDNS = "dns"
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
list list.Model
|
||||
selectedDomain *porkbun.Domain
|
||||
}
|
||||
|
||||
func New() Model {
|
||||
items := []list.Item{
|
||||
menuItem{title: "View Details", desc: "View domain registration details", id: actionDetails},
|
||||
menuItem{title: "View DNS Records", desc: "Manage DNS records", id: actionDNS},
|
||||
}
|
||||
|
||||
l := list.New(items, list.NewDefaultDelegate(), 0, 0)
|
||||
l.SetShowHelp(false)
|
||||
l.Title = "Domain Actions"
|
||||
|
||||
return Model{
|
||||
list: l,
|
||||
}
|
||||
}
|
||||
|
||||
func (m Model) Init() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
m.list.SetWidth(msg.Width)
|
||||
m.list.SetHeight(msg.Height)
|
||||
|
||||
case messages.DomainSelectedMsg:
|
||||
m.selectedDomain = msg.Domain
|
||||
m.list.Title = fmt.Sprintf("Actions for %s", m.selectedDomain.Domain)
|
||||
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "esc":
|
||||
return m, func() tea.Msg {
|
||||
return messages.SwitchPageMsg{Page: messages.PageListDomains}
|
||||
}
|
||||
case "enter":
|
||||
i, ok := m.list.SelectedItem().(menuItem)
|
||||
if ok {
|
||||
switch i.id {
|
||||
case actionDetails:
|
||||
return m, func() tea.Msg {
|
||||
return messages.SwitchPageMsg{Page: messages.PageDomainDetails}
|
||||
}
|
||||
case actionDNS:
|
||||
return m, func() tea.Msg {
|
||||
return messages.SwitchPageMsg{Page: messages.PageDNSList}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cmd tea.Cmd
|
||||
m.list, cmd = m.list.Update(msg)
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
func (m Model) View() string {
|
||||
if m.selectedDomain == nil {
|
||||
return "No domain selected"
|
||||
}
|
||||
return m.list.View()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue