Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
Fixed Edit failing when using YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-alvarenga committed Sep 6, 2022
1 parent 5d8d43a commit 309a076
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions cli/cliopts/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func getEditInfo() (n, old task.Task) {
index, priority := getTaskIndex(choice)
tasks := ng.GetTasks()[priority]
old = (*tasks)[index]
n = old

p, s := getAllPriorities(), getAllStatuses()
t := old.Title
Expand Down
26 changes: 14 additions & 12 deletions ng/ngops/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package ngops

import (
"errors"
"fmt"
"time"

"github.com/leo-alvarenga/to-go/ng"
"github.com/leo-alvarenga/to-go/ng/storage"
"github.com/leo-alvarenga/to-go/shared/task"
)

func Edit(old, n task.Task) error {
func Edit(n, old task.Task) error {
if n.Status == task.Statuses["done"] {
n.FinishedIn = getDateInToGosFmt(time.Now().Date())
}
Expand All @@ -22,7 +21,6 @@ func Edit(old, n task.Task) error {
tasks := ng.GetTasks()[old.Priority]
index := -1
for i, item := range *tasks {
fmt.Println(item.Title, old.Title)
if item.Title == old.Title {
index = i
break
Expand All @@ -37,15 +35,19 @@ func Edit(old, n task.Task) error {
}
} else {
if index >= 0 {
t1, t2 := (*tasks)[:index-1], (*tasks)[index+1:]
tasks = new([]task.Task)

for _, item := range t1 {
*tasks = append(*tasks, item)
}

for _, item := range t2 {
*tasks = append(*tasks, item)
if len(*tasks) > 1 {
tasks = new([]task.Task)
t1, t2 := (*tasks)[:index-1], (*tasks)[index+1:]

for _, item := range t1 {
*tasks = append(*tasks, item)
}

for _, item := range t2 {
*tasks = append(*tasks, item)
}
} else {
tasks = new([]task.Task)
}

storage.WriteToYamlFile(ng.TaskFilenamesMapped[old.Priority], tasks)
Expand Down

0 comments on commit 309a076

Please sign in to comment.