Browse Source

Reimplemented edit widget constructor

arianagiroux 2 tuần trước cách đây
mục cha
commit
8e61321467
1 tập tin đã thay đổi với 28 bổ sung73 xóa
  1. 28 73
      tui.go

+ 28 - 73
tui.go

@@ -134,6 +134,31 @@ func (m Model) View() string {
 	return output
 }
 
+// Handles load logic
+func (m Model) load() tea.Msg {
+	if IsIssue(m.Path) {
+		issue, err := Issue{}.NewFromPath(m.Path)
+
+		if err != nil {
+			return nil
+		}
+
+		return issue
+	}
+
+	if IsIssueCollection(m.Path) {
+		collection, err := IssueCollection{}.NewFromPath(m.Path)
+
+		if err != nil {
+			return nil
+		}
+
+		return collection
+	}
+
+	return newEditWidget(m.Path)
+}
+
 // WIDGET DEFINITIONS ---------------------------------------------------------
 // ----------------------------------------------------------------------------
 
@@ -171,49 +196,6 @@ type edit struct {
 	err         error // not implemented
 }
 
-// constructor for create widget
-func newEditBlank(path string, placeholder string) widget { // TODO DEPRECATE
-	spawnInput := func(f bool) textinput.Model {
-		ti := textinput.New()
-		ti.Placeholder = placeholder
-		if f {
-			ti.Focus()
-		}
-		ti.CharLimit = 80
-		ti.Width = 30
-		return ti
-	}
-
-	var inputs []inputField
-	for i, t := range [4]string{"title", "status", "tags", "blockers"} {
-		if i == 0 {
-			inputs = append(inputs, inputField{title: t, input: spawnInput(true)})
-		} else {
-			inputs = append(inputs, inputField{title: t, input: spawnInput(false)})
-		}
-
-		switch t {
-		case "title":
-			parsed := parsePathToHuman(path)
-
-			if parsed == "." {
-				parsed = ""
-			}
-
-			inputs[i].input.SetValue(parsed)
-		case "status":
-			inputs[i].input.SetValue("open")
-		}
-	}
-
-	return edit{
-		inputFields: inputs,
-		Path:        path,
-		selected:    0,
-		err:         nil,
-	}
-}
-
 func newEditWidget(path string) widget {
 	// data prep
 	var e edit
@@ -269,9 +251,10 @@ func newEditWidget(path string) widget {
 	input = spawnInput(false)
 	input.SetValue(issue.Blockedby.AsString())
 	input.Placeholder = "blockers, separated by comma"
-	fields = append(fields, inputField{input: input, title: "blockedby"})
+	fields = append(fields, inputField{input: input, title: "blockers"})
 
 	e.inputFields = fields
+	e.Path = path
 
 	return e
 }
@@ -674,7 +657,7 @@ func (w createInCollection) update(msg tea.Msg) (widget, tea.Cmd) {
 
 func (w createInCollection) create() tea.Msg {
 	w.Path = filepath.Join(w.Path, w.name)
-	return newEditBlank(w.Path, "lorem ipsum")
+	return newEditWidget(w.Path)
 }
 
 func (w createInCollection) render() tea.Msg {
@@ -683,31 +666,3 @@ func (w createInCollection) render() tea.Msg {
 }
 
 func (w createInCollection) keyhelp() string { return "enter: submit\t\tctrl+c: quit" }
-
-// tea.Cmd definitions --------------------------------------------------------
-// ----------------------------------------------------------------------------
-
-// Handles load logic
-func (m Model) load() tea.Msg {
-	if IsIssue(m.Path) {
-		issue, err := Issue{}.NewFromPath(m.Path)
-
-		if err != nil {
-			return nil
-		}
-
-		return issue
-	}
-
-	if IsIssueCollection(m.Path) {
-		collection, err := IssueCollection{}.NewFromPath(m.Path)
-
-		if err != nil {
-			return nil
-		}
-
-		return collection
-	}
-
-	return newEditWidget(m.Path)
-}