From 55675e0c1b4a74286115489e6db778f6ba23dee1 Mon Sep 17 00:00:00 2001 From: juancwu Date: Mon, 26 Jan 2026 18:20:09 +0000 Subject: [PATCH] remove pointer reference for models --- internal/ui/model.go | 26 +++++++++----------------- internal/ui/pages/listdomains/model.go | 10 +++++----- internal/ui/pages/login/model.go | 26 +++++++++++++------------- internal/ui/pages/menu/model.go | 10 +++++----- 4 files changed, 32 insertions(+), 40 deletions(-) diff --git a/internal/ui/model.go b/internal/ui/model.go index ab20255..cd225de 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -15,10 +15,10 @@ import ( type MainModel struct { currentPage messages.Page - login *login.Model - menu *menu.Model - listDomains *listdomains.Model - dnsRetrieve dns.RetrieveModel + login tea.Model + menu tea.Model + listDomains tea.Model + dnsRetrieve tea.Model isMenuInit bool width int height int @@ -61,8 +61,7 @@ func (m MainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.listDomains = listdomains.New(msg.Client) m.dnsRetrieve = dns.NewRetrieveModel(msg.Client) if m.width > 0 && m.height > 0 { - newMenu, _ := m.menu.Update(tea.WindowSizeMsg{Width: m.width, Height: m.height}) - m.menu = newMenu.(*menu.Model) + m.menu, _ = m.menu.Update(tea.WindowSizeMsg{Width: m.width, Height: m.height}) } m.currentPage = messages.PageMenu m.isMenuInit = true @@ -73,22 +72,15 @@ func (m MainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.currentPage = messages.PageDNSRetrieve } - var newModel tea.Model switch m.currentPage { case messages.PageLogin: - var newLogin tea.Model - newLogin, cmd = m.login.Update(msg) - m.login = newLogin.(*login.Model) + m.login, cmd = m.login.Update(msg) case messages.PageMenu: - var newMenu tea.Model - newMenu, cmd = m.menu.Update(msg) - m.menu = newMenu.(*menu.Model) + m.menu, cmd = m.menu.Update(msg) case messages.PageListDomains: - newModel, cmd = m.listDomains.Update(msg) - m.listDomains = newModel.(*listdomains.Model) + m.listDomains, cmd = m.listDomains.Update(msg) case messages.PageDNSRetrieve: - newModel, cmd = m.dnsRetrieve.Update(msg) - m.dnsRetrieve = newModel.(dns.RetrieveModel) + m.dnsRetrieve, cmd = m.dnsRetrieve.Update(msg) } cmds = append(cmds, cmd) diff --git a/internal/ui/pages/listdomains/model.go b/internal/ui/pages/listdomains/model.go index 0b9ccec..a60a251 100644 --- a/internal/ui/pages/listdomains/model.go +++ b/internal/ui/pages/listdomains/model.go @@ -21,7 +21,7 @@ type Model struct { stderr string } -func New(client *porkbun.Client) *Model { +func New(client *porkbun.Client) Model { p := paginator.New() p.Type = paginator.Dots p.PerPage = 1 @@ -32,7 +32,7 @@ func New(client *porkbun.Client) *Model { s.Spinner = spinner.Dot s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205")) - return &Model{ + return Model{ loading: false, client: client, domains: nil, @@ -41,11 +41,11 @@ func New(client *porkbun.Client) *Model { } } -func (m *Model) Init() tea.Cmd { +func (m Model) Init() tea.Cmd { return m.spinner.Tick } -func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { @@ -89,7 +89,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil } -func (m *Model) View() string { +func (m Model) View() string { if m.stderr != "" { return fmt.Sprintf("%s\n\n(Press ctrl+c to quit)", m.stderr) } diff --git a/internal/ui/pages/login/model.go b/internal/ui/pages/login/model.go index 95fd4de..581eb4b 100644 --- a/internal/ui/pages/login/model.go +++ b/internal/ui/pages/login/model.go @@ -26,7 +26,7 @@ type Model struct { err error } -func New(cfg *config.Config) *Model { +func New(cfg *config.Config) Model { m := Model{ cfg: cfg, } @@ -60,14 +60,14 @@ func New(cfg *config.Config) *Model { m.inputs[2].Width = 50 } - return &m + return m } -func (m *Model) Init() tea.Cmd { +func (m Model) Init() tea.Cmd { return textinput.Blink } -func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { @@ -109,15 +109,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } -func (m *Model) updateInputs(msg tea.Msg) tea.Cmd { - cmds := make([]tea.Cmd, len(m.inputs)) - for i := range m.inputs { - m.inputs[i], cmds[i] = m.inputs[i].Update(msg) - } - return tea.Batch(cmds...) -} - -func (m *Model) View() string { +func (m Model) View() string { var b strings.Builder if m.mode == ModeSetup { @@ -190,3 +182,11 @@ func (m *Model) submit() (tea.Model, tea.Cmd) { return messages.SessionReadyMsg{Client: client} } } + +func (m *Model) updateInputs(msg tea.Msg) tea.Cmd { + cmds := make([]tea.Cmd, len(m.inputs)) + for i := range m.inputs { + m.inputs[i], cmds[i] = m.inputs[i].Update(msg) + } + return tea.Batch(cmds...) +} diff --git a/internal/ui/pages/menu/model.go b/internal/ui/pages/menu/model.go index 9dbd1b8..5c3feef 100644 --- a/internal/ui/pages/menu/model.go +++ b/internal/ui/pages/menu/model.go @@ -53,7 +53,7 @@ type Model struct { output string } -func New(client *porkbun.Client) *Model { +func New(client *porkbun.Client) Model { items := []list.Item{ menuItem{id: domainListAll, title: "Domain: List All", desc: "List all domains in your account"}, menuItem{id: dnsRetrieveRecords, title: "DNS: Retrieve Records", desc: "Retrieve DNS records for a domain"}, @@ -81,7 +81,7 @@ func New(client *porkbun.Client) *Model { ti.CharLimit = 156 ti.Width = 20 - return &Model{ + return Model{ list: l, paginator: p, spinner: s, @@ -91,11 +91,11 @@ func New(client *porkbun.Client) *Model { } } -func (m *Model) Init() tea.Cmd { +func (m Model) Init() tea.Cmd { return tea.Sequence(m.spinner.Tick) } -func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.WindowSizeMsg: m.list.SetWidth(msg.Width) @@ -138,7 +138,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } -func (m *Model) View() string { +func (m Model) View() string { if m.loading { return fmt.Sprintf("\n\n %s Loading... press ctl+c to quit\n\n", m.spinner.View()) }