refactor: rename all model to Model

This commit is contained in:
Slug-Boi
2025-04-17 23:08:42 +02:00
committed by Theis
parent 8b3c5ab539
commit 39a5005a39
3 changed files with 76 additions and 83 deletions
+9 -11
View File
@@ -52,7 +52,7 @@ func errorGetMissingFields(m model_ca) {
if len(m.inputs) > 0 { if len(m.inputs) > 0 {
for i := 0; i < inpLen; i++ { for i := 0; i < inpLen; i++ {
if m.inputs[i].Value() == "" { if m.inputs[i].Value() == "" {
m.errorModel.missing = append(m.errorModel.missing, "- "+strings.Split(m.inputs[i].Placeholder," (")[0]) m.errorModel.missing = append(m.errorModel.missing, "- "+strings.Split(m.inputs[i].Placeholder, " (")[0])
} }
} }
} else { } else {
@@ -74,7 +74,6 @@ func (e errorModel) View() string {
lipgloss.Left, // Changed from Center to Left for better alignment lipgloss.Left, // Changed from Center to Left for better alignment
sb.String(), sb.String(),
"\n\n[enter/esc]", "\n\n[enter/esc]",
) )
// Create the error box // Create the error box
@@ -93,9 +92,9 @@ func (e errorModel) View() string {
Render(errorBox) Render(errorBox)
} }
var parent_m *model var parent_m *Model
func createAuthorModel(old_m *model) model_ca { func createAuthorModel(old_m *Model) model_ca {
parent_m = old_m parent_m = old_m
m := model_ca{ m := model_ca{
@@ -137,7 +136,7 @@ func intitialErrorModel() *errorModel {
} }
} }
func createGHTempAuthorModel(old_m *model, user utils.User) model_ca { func createGHTempAuthorModel(old_m *Model, user utils.User) model_ca {
parent_m = old_m parent_m = old_m
m := model_ca{ m := model_ca{
inputs: make([]textinput.Model, 2), inputs: make([]textinput.Model, 2),
@@ -164,7 +163,7 @@ func createGHTempAuthorModel(old_m *model, user utils.User) model_ca {
return m return m
} }
func createGHAuthorModel(old_m *model, user utils.User) model_ca { func createGHAuthorModel(old_m *Model, user utils.User) model_ca {
parent_m = old_m parent_m = old_m
m := model_ca{ m := model_ca{
@@ -205,7 +204,7 @@ func createGHAuthorModel(old_m *model, user utils.User) model_ca {
} }
func EntryGHAuthorModel(user utils.User) { func EntryGHAuthorModel(user utils.User) {
model := createGHAuthorModel(&model{}, user) model := createGHAuthorModel(&Model{}, user)
print(model.inputs[0].Value()) print(model.inputs[0].Value())
@@ -215,8 +214,7 @@ func EntryGHAuthorModel(user utils.User) {
} }
} }
func tempAuthorModel(old_m *Model) model_ca {
func tempAuthorModel(old_m *model) model_ca {
parent_m = old_m parent_m = old_m
m := model_ca{ m := model_ca{
@@ -297,7 +295,7 @@ func (m model_ca) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil return m, nil
} }
if parent_m != nil { if parent_m != nil {
return model{list: parent_m.list}, tea.ClearScreen return Model{list: parent_m.list}, tea.ClearScreen
} else { } else {
m.quitting = true m.quitting = true
return m, tea.Quit return m, tea.Quit
@@ -317,7 +315,7 @@ func (m model_ca) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} }
if parent_m.keys != nil { if parent_m.keys != nil {
tempAuthorToggle = false tempAuthorToggle = false
return model{list: parent_m.list}, tea.ClearScreen return Model{list: parent_m.list}, tea.ClearScreen
} else { } else {
m.quitting = true m.quitting = true
tempAuthorToggle = false tempAuthorToggle = false
+3 -5
View File
@@ -27,7 +27,7 @@ type GitHubUserModel struct {
tempAuth bool tempAuth bool
} }
func NewGitHubUserForm(old_m *model) GitHubUserModel { func NewGitHubUserForm(old_m *Model) GitHubUserModel {
parent_m = old_m parent_m = old_m
m := GitHubUserModel{ m := GitHubUserModel{
@@ -35,7 +35,6 @@ func NewGitHubUserForm(old_m *model) GitHubUserModel {
tempAuthShow: func() bool { tempAuthShow: func() bool {
return old_m != nil return old_m != nil
}(), }(),
} }
// GitHub Username (required) // GitHub Username (required)
@@ -91,9 +90,9 @@ func (m GitHubUserModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
user.Email = m.inputs[1].Value() user.Email = m.inputs[1].Value()
} }
if m.tempAuth { if m.tempAuth {
return createGHTempAuthorModel(parent_m,user), tea.ClearScreen return createGHTempAuthorModel(parent_m, user), tea.ClearScreen
} }
return createGHAuthorModel(parent_m,user), tea.ClearScreen return createGHAuthorModel(parent_m, user), tea.ClearScreen
} else if s == "enter" && m.focusIndex == len(m.inputs) && m.tempAuthShow { } else if s == "enter" && m.focusIndex == len(m.inputs) && m.tempAuthShow {
//toggle temp mode //toggle temp mode
@@ -101,7 +100,6 @@ func (m GitHubUserModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil return m, nil
} }
// Cycle through inputs // Cycle through inputs
if s == "up" || s == "shift+tab" { if s == "up" || s == "shift+tab" {
m.focusIndex-- m.focusIndex--
+11 -14
View File
@@ -148,7 +148,7 @@ func TestEntryTA(t *testing.T) {
keyPress(tm, "esc") keyPress(tm, "esc")
fm := tm.FinalModel(t) fm := tm.FinalModel(t)
m, ok := fm.(model) m, ok := fm.(Model)
if !ok { if !ok {
t.Errorf("Expected model_ca, got %T", fm) t.Errorf("Expected model_ca, got %T", fm)
} }
@@ -242,7 +242,7 @@ func Test_EntryCA_TriggerError(t *testing.T) {
keyPress(tm, "esc") keyPress(tm, "esc")
fm := tm.FinalModel(t) fm := tm.FinalModel(t)
mm, ok := fm.(model) mm, ok := fm.(Model)
if !ok { if !ok {
t.Errorf("Expected model_ca, got %T", fm) t.Errorf("Expected model_ca, got %T", fm)
} }
@@ -285,7 +285,7 @@ func Test_EntryCA(t *testing.T) {
keyPress(tm, "esc") keyPress(tm, "esc")
fm := tm.FinalModel(t) fm := tm.FinalModel(t)
m, ok := fm.(model) m, ok := fm.(Model)
if !ok { if !ok {
t.Errorf("Expected model, got %T", fm) t.Errorf("Expected model, got %T", fm)
} }
@@ -397,7 +397,6 @@ func TestSubmitWithRequiredField(t *testing.T) {
setup() setup()
defer teardown() defer teardown()
m := NewGitHubUserForm(nil) m := NewGitHubUserForm(nil)
tm := teatest.NewTestModel( tm := teatest.NewTestModel(
t, m, teatest.WithInitialTermSize(300, 300), t, m, teatest.WithInitialTermSize(300, 300),
@@ -421,8 +420,6 @@ func TestSubmitWithRequiredField(t *testing.T) {
// Check if the form was submitted // Check if the form was submitted
updated, _ := tm.FinalModel(t).(model_ca) updated, _ := tm.FinalModel(t).(model_ca)
if updated.inputs[0].Value() != "th" { if updated.inputs[0].Value() != "th" {
t.Errorf("Expected 'Slug-Boi', got '%s'", updated.inputs[0].Value()) t.Errorf("Expected 'Slug-Boi', got '%s'", updated.inputs[0].Value())
} }
@@ -440,7 +437,7 @@ func TestSubmitWithRequiredField(t *testing.T) {
// Test temp auth toggle visibility // Test temp auth toggle visibility
func TestTempAuthToggleVisibility(t *testing.T) { func TestTempAuthToggleVisibility(t *testing.T) {
// With parent model (should show toggle) // With parent model (should show toggle)
m1 := NewGitHubUserForm(&model{}) m1 := NewGitHubUserForm(&Model{})
if !m1.tempAuthShow { if !m1.tempAuthShow {
t.Error("tempAuthShow should be true with parent model") t.Error("tempAuthShow should be true with parent model")
} }
@@ -454,7 +451,7 @@ func TestTempAuthToggleVisibility(t *testing.T) {
// Test temp auth toggle functionality // Test temp auth toggle functionality
func TestTempAuthToggle(t *testing.T) { func TestTempAuthToggle(t *testing.T) {
m := NewGitHubUserForm(&model{}) m := NewGitHubUserForm(&Model{})
// Initial state // Initial state
if m.tempAuth { if m.tempAuth {
@@ -610,7 +607,7 @@ func Test_EntrySelectUsers(t *testing.T) {
keyPress(tm, "enter") keyPress(tm, "enter")
fm := tm.FinalModel(t) fm := tm.FinalModel(t)
m, ok := fm.(model) m, ok := fm.(Model)
if !ok { if !ok {
t.Errorf("Expected model, got %T", fm) t.Errorf("Expected model, got %T", fm)
} }
@@ -640,7 +637,7 @@ func Test_EntrySelectAll(t *testing.T) {
keyPress(tm, "enter") keyPress(tm, "enter")
fm := tm.FinalModel(t) fm := tm.FinalModel(t)
m, ok := fm.(model) m, ok := fm.(Model)
if !ok { if !ok {
t.Errorf("Expected model, got %T", fm) t.Errorf("Expected model, got %T", fm)
} }
@@ -669,7 +666,7 @@ func Test_EntryNegation(t *testing.T) {
keyPress(tm, "enter") keyPress(tm, "enter")
fm := tm.FinalModel(t) fm := tm.FinalModel(t)
m, ok := fm.(model) m, ok := fm.(Model)
if !ok { if !ok {
t.Errorf("Expected model, got %T", fm) t.Errorf("Expected model, got %T", fm)
} }
@@ -700,7 +697,7 @@ func Test_EntryDeleteAuthor(t *testing.T) {
keyPress(tm, "enter") keyPress(tm, "enter")
fm := tm.FinalModel(t) fm := tm.FinalModel(t)
m, ok := fm.(model) m, ok := fm.(Model)
if !ok { if !ok {
t.Errorf("Expected model, got %T", fm) t.Errorf("Expected model, got %T", fm)
} }
@@ -733,7 +730,7 @@ func Test_GroupSelection(t *testing.T) {
keyPress(tm, "enter") keyPress(tm, "enter")
fm := tm.FinalModel(t) fm := tm.FinalModel(t)
_, ok := fm.(model) _, ok := fm.(Model)
if !ok { if !ok {
t.Errorf("Expected model, got %T", fm) t.Errorf("Expected model, got %T", fm)
} }
@@ -769,7 +766,7 @@ func Test_pagination(t *testing.T) {
tm.Quit() tm.Quit()
fm := tm.FinalModel(t) fm := tm.FinalModel(t)
m, ok := fm.(model) m, ok := fm.(Model)
if !ok { if !ok {
t.Errorf("Expected model, got %T", fm) t.Errorf("Expected model, got %T", fm)
} }