remove pointer reference for models
This commit is contained in:
parent
a6bcb9be38
commit
55675e0c1b
4 changed files with 32 additions and 40 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue