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 {
|
type MainModel struct {
|
||||||
currentPage messages.Page
|
currentPage messages.Page
|
||||||
login *login.Model
|
login tea.Model
|
||||||
menu *menu.Model
|
menu tea.Model
|
||||||
listDomains *listdomains.Model
|
listDomains tea.Model
|
||||||
dnsRetrieve dns.RetrieveModel
|
dnsRetrieve tea.Model
|
||||||
isMenuInit bool
|
isMenuInit bool
|
||||||
width int
|
width int
|
||||||
height 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.listDomains = listdomains.New(msg.Client)
|
||||||
m.dnsRetrieve = dns.NewRetrieveModel(msg.Client)
|
m.dnsRetrieve = dns.NewRetrieveModel(msg.Client)
|
||||||
if m.width > 0 && m.height > 0 {
|
if m.width > 0 && m.height > 0 {
|
||||||
newMenu, _ := m.menu.Update(tea.WindowSizeMsg{Width: m.width, Height: m.height})
|
m.menu, _ = m.menu.Update(tea.WindowSizeMsg{Width: m.width, Height: m.height})
|
||||||
m.menu = newMenu.(*menu.Model)
|
|
||||||
}
|
}
|
||||||
m.currentPage = messages.PageMenu
|
m.currentPage = messages.PageMenu
|
||||||
m.isMenuInit = true
|
m.isMenuInit = true
|
||||||
|
|
@ -73,22 +72,15 @@ func (m MainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
m.currentPage = messages.PageDNSRetrieve
|
m.currentPage = messages.PageDNSRetrieve
|
||||||
}
|
}
|
||||||
|
|
||||||
var newModel tea.Model
|
|
||||||
switch m.currentPage {
|
switch m.currentPage {
|
||||||
case messages.PageLogin:
|
case messages.PageLogin:
|
||||||
var newLogin tea.Model
|
m.login, cmd = m.login.Update(msg)
|
||||||
newLogin, cmd = m.login.Update(msg)
|
|
||||||
m.login = newLogin.(*login.Model)
|
|
||||||
case messages.PageMenu:
|
case messages.PageMenu:
|
||||||
var newMenu tea.Model
|
m.menu, cmd = m.menu.Update(msg)
|
||||||
newMenu, cmd = m.menu.Update(msg)
|
|
||||||
m.menu = newMenu.(*menu.Model)
|
|
||||||
case messages.PageListDomains:
|
case messages.PageListDomains:
|
||||||
newModel, cmd = m.listDomains.Update(msg)
|
m.listDomains, cmd = m.listDomains.Update(msg)
|
||||||
m.listDomains = newModel.(*listdomains.Model)
|
|
||||||
case messages.PageDNSRetrieve:
|
case messages.PageDNSRetrieve:
|
||||||
newModel, cmd = m.dnsRetrieve.Update(msg)
|
m.dnsRetrieve, cmd = m.dnsRetrieve.Update(msg)
|
||||||
m.dnsRetrieve = newModel.(dns.RetrieveModel)
|
|
||||||
}
|
}
|
||||||
cmds = append(cmds, cmd)
|
cmds = append(cmds, cmd)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ type Model struct {
|
||||||
stderr string
|
stderr string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *porkbun.Client) *Model {
|
func New(client *porkbun.Client) Model {
|
||||||
p := paginator.New()
|
p := paginator.New()
|
||||||
p.Type = paginator.Dots
|
p.Type = paginator.Dots
|
||||||
p.PerPage = 1
|
p.PerPage = 1
|
||||||
|
|
@ -32,7 +32,7 @@ func New(client *porkbun.Client) *Model {
|
||||||
s.Spinner = spinner.Dot
|
s.Spinner = spinner.Dot
|
||||||
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
|
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
|
||||||
|
|
||||||
return &Model{
|
return Model{
|
||||||
loading: false,
|
loading: false,
|
||||||
client: client,
|
client: client,
|
||||||
domains: nil,
|
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
|
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
|
var cmd tea.Cmd
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
|
|
@ -89,7 +89,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) View() string {
|
func (m Model) View() string {
|
||||||
if m.stderr != "" {
|
if m.stderr != "" {
|
||||||
return fmt.Sprintf("%s\n\n(Press ctrl+c to quit)", m.stderr)
|
return fmt.Sprintf("%s\n\n(Press ctrl+c to quit)", m.stderr)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ type Model struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *config.Config) *Model {
|
func New(cfg *config.Config) Model {
|
||||||
m := Model{
|
m := Model{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
}
|
}
|
||||||
|
|
@ -60,14 +60,14 @@ func New(cfg *config.Config) *Model {
|
||||||
m.inputs[2].Width = 50
|
m.inputs[2].Width = 50
|
||||||
}
|
}
|
||||||
|
|
||||||
return &m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) Init() tea.Cmd {
|
func (m Model) Init() tea.Cmd {
|
||||||
return textinput.Blink
|
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) {
|
switch msg := msg.(type) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
|
|
@ -109,15 +109,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
return m, cmd
|
return m, cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) updateInputs(msg tea.Msg) tea.Cmd {
|
func (m Model) View() string {
|
||||||
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 {
|
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
|
|
||||||
if m.mode == ModeSetup {
|
if m.mode == ModeSetup {
|
||||||
|
|
@ -190,3 +182,11 @@ func (m *Model) submit() (tea.Model, tea.Cmd) {
|
||||||
return messages.SessionReadyMsg{Client: client}
|
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
|
output string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(client *porkbun.Client) *Model {
|
func New(client *porkbun.Client) Model {
|
||||||
items := []list.Item{
|
items := []list.Item{
|
||||||
menuItem{id: domainListAll, title: "Domain: List All", desc: "List all domains in your account"},
|
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"},
|
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.CharLimit = 156
|
||||||
ti.Width = 20
|
ti.Width = 20
|
||||||
|
|
||||||
return &Model{
|
return Model{
|
||||||
list: l,
|
list: l,
|
||||||
paginator: p,
|
paginator: p,
|
||||||
spinner: s,
|
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)
|
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) {
|
switch msg := msg.(type) {
|
||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
m.list.SetWidth(msg.Width)
|
m.list.SetWidth(msg.Width)
|
||||||
|
|
@ -138,7 +138,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
return m, cmd
|
return m, cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) View() string {
|
func (m Model) View() string {
|
||||||
if m.loading {
|
if m.loading {
|
||||||
return fmt.Sprintf("\n\n %s Loading... press ctl+c to quit\n\n", m.spinner.View())
|
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