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

View file

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