Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

section_id is messed up when listing items #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/fatih/color"
"github.com/sachaos/todoist/lib"
todoist "github.com/sachaos/todoist/lib"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -105,15 +105,21 @@ func ProjectFormat(id int, store *todoist.Store, projectColorHash map[int]color.
return prefix + color.New(projectColorHash[project.GetID()]).SprintFunc()("#"+namePrefix+projectName)
}

func SectionFormat(id int, store *todoist.Store, c *cli.Context) string {
prefix := ""
sectionName := ""
section := store.FindSection(id)
if section != nil {
prefix = "/"
sectionName = section.Name
func SectionFormat(id interface{}, store *todoist.Store, c *cli.Context) string {
if id == nil {
return ""
} else {
prefix := ""
sectionName := ""
// section id is an empty interface, it will be unmarshalled as float64 instead of int
// refer to https://golang.org/pkg/encoding/json/#Unmarshal for details
section := store.FindSection(int(id.(float64)))
if section != nil {
prefix = "/"
sectionName = section.Name
}
return prefix + sectionName
}
return prefix + sectionName
}

func dueDateString(dueDate time.Time, allDay bool) string {
Expand Down
3 changes: 2 additions & 1 deletion lib/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ type HaveProjectID struct {
ProjectID int `json:"project_id"`
}

// HaveSectionID defines the ID of the section that item belongs to, it can be emtpy(nul)
type HaveSectionID struct {
SectionID int `json:"section_id"`
SectionID interface{} `json:"section_id"`
}

type HaveIndent struct {
Expand Down