mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
refactor: rename all model to Model
This commit is contained in:
+32
-34
@@ -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 {
|
||||||
@@ -69,37 +69,36 @@ func (e errorModel) View() string {
|
|||||||
sb.WriteString(strings.Join(e.missing, "\n"))
|
sb.WriteString(strings.Join(e.missing, "\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create centered content
|
// Create centered content
|
||||||
content := lipgloss.JoinVertical(
|
content := lipgloss.JoinVertical(
|
||||||
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
|
||||||
|
errorBox := lipgloss.NewStyle().
|
||||||
// Create the error box
|
Border(lipgloss.RoundedBorder()).
|
||||||
errorBox := lipgloss.NewStyle().
|
BorderForeground(lipgloss.Color("9")).
|
||||||
Border(lipgloss.RoundedBorder()).
|
Padding(1, 2).
|
||||||
BorderForeground(lipgloss.Color("9")).
|
Width(40).
|
||||||
Padding(1, 2).
|
Foreground(lipgloss.Color("9")).
|
||||||
Width(40).
|
Background(lipgloss.Color("0")).
|
||||||
Foreground(lipgloss.Color("9")).
|
|
||||||
Background(lipgloss.Color("0")).
|
|
||||||
Align(lipgloss.Center).
|
Align(lipgloss.Center).
|
||||||
Render(content)
|
Render(content)
|
||||||
|
|
||||||
return lipgloss.NewStyle().
|
return lipgloss.NewStyle().
|
||||||
Padding(1, 0).
|
Padding(1, 0).
|
||||||
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{
|
||||||
inputs: make([]textinput.Model, 5),
|
inputs: make([]textinput.Model, 5),
|
||||||
errorModel: intitialErrorModel(),
|
errorModel: intitialErrorModel(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,10 +136,10 @@ 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),
|
||||||
errorModel: intitialErrorModel(),
|
errorModel: intitialErrorModel(),
|
||||||
}
|
}
|
||||||
var t textinput.Model
|
var t textinput.Model
|
||||||
@@ -164,11 +163,11 @@ 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{
|
||||||
inputs: make([]textinput.Model, 5),
|
inputs: make([]textinput.Model, 5),
|
||||||
errorModel: intitialErrorModel(),
|
errorModel: intitialErrorModel(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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,12 +214,11 @@ 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{
|
||||||
inputs: make([]textinput.Model, 2),
|
inputs: make([]textinput.Model, 2),
|
||||||
errorModel: intitialErrorModel(),
|
errorModel: intitialErrorModel(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,8 +295,8 @@ 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
|
||||||
@@ -455,7 +453,7 @@ func (m *model_ca) AddAuthor() bool {
|
|||||||
Username: m.inputs[2].Value(),
|
Username: m.inputs[2].Value(),
|
||||||
Email: m.inputs[3].Value(),
|
Email: m.inputs[3].Value(),
|
||||||
Ex: m.exclude,
|
Ex: m.exclude,
|
||||||
Groups: groups,
|
Groups: groups,
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.CreateAuthor(usr)
|
utils.CreateAuthor(usr)
|
||||||
|
|||||||
+18
-20
@@ -12,22 +12,22 @@ import (
|
|||||||
|
|
||||||
// Styles
|
// Styles
|
||||||
var (
|
var (
|
||||||
errorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("9"))
|
errorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("9"))
|
||||||
toggleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("99"))
|
toggleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("99"))
|
||||||
activeToggleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
|
activeToggleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
|
||||||
)
|
)
|
||||||
|
|
||||||
type GitHubUserModel struct {
|
type GitHubUserModel struct {
|
||||||
inputs []textinput.Model
|
inputs []textinput.Model
|
||||||
focusIndex int
|
focusIndex int
|
||||||
submitted bool
|
submitted bool
|
||||||
showError bool
|
showError bool
|
||||||
errorMsg string
|
errorMsg string
|
||||||
tempAuthShow bool
|
tempAuthShow bool
|
||||||
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)
|
||||||
@@ -70,7 +69,7 @@ func (m GitHubUserModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
case "ctrl+t": // Toggle temp mode
|
case "ctrl+t": // Toggle temp mode
|
||||||
if m.tempAuthShow {
|
if m.tempAuthShow {
|
||||||
m.tempAuth = !m.tempAuth
|
m.tempAuth = !m.tempAuth
|
||||||
return m, nil
|
return m, nil
|
||||||
@@ -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,12 +100,11 @@ 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--
|
||||||
} else {
|
} else {
|
||||||
m.focusIndex++
|
m.focusIndex++
|
||||||
}
|
}
|
||||||
|
|
||||||
inpNum := len(m.inputs)
|
inpNum := len(m.inputs)
|
||||||
@@ -181,11 +179,11 @@ func (m GitHubUserModel) View() string {
|
|||||||
|
|
||||||
toggleBtn := fmt.Sprintf("[ TempAuthor ] %s ", toggleText)
|
toggleBtn := fmt.Sprintf("[ TempAuthor ] %s ", toggleText)
|
||||||
|
|
||||||
if m.focusIndex == len(m.inputs) { // When toggle is focused
|
if m.focusIndex == len(m.inputs) { // When toggle is focused
|
||||||
b.WriteString("\n" + focusedStyle.Render(toggleBtn))
|
b.WriteString("\n" + focusedStyle.Render(toggleBtn))
|
||||||
} else {
|
} else {
|
||||||
b.WriteString("\n" + blurredStyle.Render(toggleBtn))
|
b.WriteString("\n" + blurredStyle.Render(toggleBtn))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit button
|
// Submit button
|
||||||
|
|||||||
+13
-16
@@ -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),
|
||||||
@@ -405,8 +404,8 @@ func TestSubmitWithRequiredField(t *testing.T) {
|
|||||||
|
|
||||||
// Simulate filling in the required field
|
// Simulate filling in the required field
|
||||||
tm.Type("Slug-Boi")
|
tm.Type("Slug-Boi")
|
||||||
tm.Send(tea.KeyMsg{Type: tea.KeyTab}) // Move to next field
|
tm.Send(tea.KeyMsg{Type: tea.KeyTab}) // Move to next field
|
||||||
tm.Send(tea.KeyMsg{Type: tea.KeyTab}) // Move to submit button
|
tm.Send(tea.KeyMsg{Type: tea.KeyTab}) // Move to submit button
|
||||||
tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) // Submit
|
tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) // Submit
|
||||||
tm.Send(tea.KeyMsg{Type: tea.KeyTab})
|
tm.Send(tea.KeyMsg{Type: tea.KeyTab})
|
||||||
tm.Send(tea.KeyMsg{Type: tea.KeyTab})
|
tm.Send(tea.KeyMsg{Type: tea.KeyTab})
|
||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user