Skip to content

Commit 24f772f

Browse files
committed
chore: refactor state name
1 parent 95b27c7 commit 24f772f

File tree

4 files changed

+32
-64
lines changed

4 files changed

+32
-64
lines changed

states/homepage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func GetHomePage() *HomePage {
2525
homePageInstance = &HomePage{}
2626
homePageInstance.once.Do(func() {
2727
homePageInstance.BaseState = BaseState{
28-
Transitions: []State{GetInitPage()}, // Ensure all transitions are properly initialized
28+
Transitions: []State{GetInitiaInit()}, // Ensure all transitions are properly initialized
2929
}
3030
})
3131
}

states/init.go

-56
This file was deleted.

states/initia_init.go

+30-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package states
22

33
import (
4+
"sync"
5+
46
tea "github.com/charmbracelet/bubbletea"
57
)
68

@@ -9,15 +11,24 @@ var _ tea.Model = &InitiaInit{}
911

1012
type InitiaInit struct {
1113
BaseState
14+
once sync.Once
1215
}
1316

14-
func NewInitiaInit(transitions []State) *InitiaInit {
15-
return &InitiaInit{
16-
BaseState: BaseState{
17-
Transitions: transitions,
18-
Name: "Run L1 Node",
19-
},
17+
// InitiaInitInstance holds the singleton instance of InitiaInit
18+
var InitiaInitInstance *InitiaInit
19+
20+
// GetInitiaInit returns the singleton instance of the InitiaInit state
21+
func GetInitiaInit() *InitiaInit {
22+
// Use sync.Once to ensure the InitiaInit is initialized only once
23+
if InitiaInitInstance == nil {
24+
InitiaInitInstance = &InitiaInit{}
25+
InitiaInitInstance.once.Do(func() {
26+
InitiaInitInstance.BaseState = BaseState{
27+
Transitions: []State{GetRunL1Node(), GetLaunchNewMinitia()}, // Initialize transitions if needed
28+
}
29+
})
2030
}
31+
return InitiaInitInstance
2132
}
2233

2334
func (ii *InitiaInit) Init() tea.Cmd {
@@ -29,5 +40,17 @@ func (ii *InitiaInit) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
2940
}
3041

3142
func (ii *InitiaInit) View() string {
32-
return ii.Name + " Page\n"
43+
view := "weave init\n\nWhat action would you like to perform?\n"
44+
for i, transition := range ii.Transitions {
45+
if i == ii.Cursor {
46+
view += "(•) " + transition.GetName() + "\n"
47+
} else {
48+
view += "( ) " + transition.GetName() + "\n"
49+
}
50+
}
51+
return view + "\nPress Enter to go to the selected page, or Q to quit."
52+
}
53+
54+
func (ii *InitiaInit) GetName() string {
55+
return "Weave Init"
3356
}

states/states_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package states_test

0 commit comments

Comments
 (0)