fix: remove "" first element

This commit is contained in:
Anish Lakhwara 2024-05-04 19:35:45 -07:00
parent b7a75c18db
commit a946a56dea
2 changed files with 15 additions and 15 deletions

21
main.go
View file

@ -18,7 +18,6 @@ import (
var ( var (
tasks = task.GetTasks() tasks = task.GetTasks()
columns = []table.Column{ columns = []table.Column{
{Title: "✅?", Width: 3},
{Title: "ID", Width: 4}, {Title: "ID", Width: 4},
{Title: "Project", Width: 10}, {Title: "Project", Width: 10},
{Title: "Tags", Width: 10}, {Title: "Tags", Width: 10},
@ -39,7 +38,7 @@ func TasksToRows(tasks []task.Task) []table.Row {
rows := make([]table.Row, len(tasks)) rows := make([]table.Row, len(tasks))
for i := 0; i < len(tasks); i++ { for i := 0; i < len(tasks); i++ {
t := tasks[i] t := tasks[i]
rows[i] = []string{"❌", strconv.Itoa(t.Id), t.Project, strings.Join(t.Tags[:], " "), t.Description} // fmt.Sprintf("%f", t.Urgency) rows[i] = []string{strconv.Itoa(t.Id), t.Project, strings.Join(t.Tags[:], " "), t.Description} // fmt.Sprintf("%f", t.Urgency)
} }
return rows return rows
} }
@ -75,10 +74,10 @@ type editorFinishedMsg struct{ err error }
func (m model) rowsToFile() []string { func (m model) rowsToFile() []string {
var rows []string var rows []string
for _, row := range m.all.Rows() { for index, row := range m.all.Rows() {
if row[0] == "✅" { if index < m.all.ActiveIndex() {
// get uuid // get uuid
id := row[1] id := row[0]
uuid_byte, err := exec.Command("task", "_get", id + ".uuid").Output() uuid_byte, err := exec.Command("task", "_get", id + ".uuid").Output()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -93,9 +92,9 @@ func (m model) rowsToFile() []string {
log.Fatal(err) log.Fatal(err)
} }
path := time.Now().Format(time.DateOnly) path := time.Now().Format(time.DateOnly)
tags := strings.Replace(row[3], " ", ":", -1) tags := strings.Replace(row[2], " ", ":", -1)
tags = ":" + row[2] + ":" + tags + ":" tags = ":" + row[1] + ":" + tags + ":"
fmt.Fprintln(f, "%title " + row[4]) fmt.Fprintln(f, "%title " + row[3])
fmt.Fprintln(f, tags) fmt.Fprintln(f, tags)
fmt.Fprintln(f, "%date " + path) fmt.Fprintln(f, "%date " + path)
fmt.Fprintln(f, "") fmt.Fprintln(f, "")
@ -103,8 +102,10 @@ func (m model) rowsToFile() []string {
} }
// link to task-note from pom-note // link to task-note from pom-note
row[4] = "[[../task-notes/" + uuid + ".wiki|" + row[4] + "]]" rowClone := make(table.Row, len(row))
rows = append(rows, strings.Join(row[2:], " - ")) _ = copy(rowClone, row)
rowClone[3] = "[[../task-notes/" + uuid + ".wiki|" + row[3] + "]]"
rows = append(rows, strings.Join(row[1:], " - "))
} }
} }
return rows return rows

View file

@ -330,11 +330,6 @@ func (m *Model) SwitchRow() {
// Get selected row // Get selected row
selectedRow := m.SelectedRow() selectedRow := m.SelectedRow()
if (selectedRow[0] == "❌") {
selectedRow[0] = "✅"
} else {
selectedRow[0] = "❌"
}
removedRows := remove(m.rows, m.cursor) removedRows := remove(m.rows, m.cursor)
// If cursor outside selection (adding selection) // If cursor outside selection (adding selection)
@ -369,6 +364,10 @@ func (m *Model) SetHeight(h int) {
m.UpdateViewport() m.UpdateViewport()
} }
func (m *Model) ActiveIndex() int {
return m.selected
}
// Height returns the viewport height of the table. // Height returns the viewport height of the table.
func (m Model) Height() int { func (m Model) Height() int {
return m.viewport.Height return m.viewport.Height