From e1f1d0a4108bd1e3f840cf933cfbd151e6469b31 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Fri, 13 Dec 2019 08:51:12 -0800 Subject: [PATCH] WTF-781 Clean up Todoist project ID handling a bit (#783) Signed-off-by: Chris Cummer --- modules/todoist/settings.go | 9 ++++++--- modules/todoist/widget.go | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/modules/todoist/settings.go b/modules/todoist/settings.go index c32c4fa4..ae554d70 100644 --- a/modules/todoist/settings.go +++ b/modules/todoist/settings.go @@ -5,6 +5,7 @@ import ( "github.com/olebedev/config" "github.com/wtfutil/wtf/cfg" + "github.com/wtfutil/wtf/utils" ) const ( @@ -12,19 +13,21 @@ const ( defaultTitle = "Todoist" ) +// Settings defines the configuration properties for this module type Settings struct { common *cfg.Common - apiKey string - projects []interface{} + apiKey string `help:"Your Todoist API key"` + projects []int } +// NewSettingsFromYAML creates a new settings instance from a YAML config block func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { settings := Settings{ common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig), apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_TODOIST_TOKEN"))), - projects: ymlConfig.UList("projects"), + projects: utils.ToInts(ymlConfig.UList("projects")), } return &settings diff --git a/modules/todoist/widget.go b/modules/todoist/widget.go index 0bb980f0..afa920cc 100644 --- a/modules/todoist/widget.go +++ b/modules/todoist/widget.go @@ -102,28 +102,28 @@ func (widget *Widget) Unselect() { /* -------------------- Keyboard Movement -------------------- */ // Close closes the currently-selected task in the currently-selected project -func (w *Widget) Close() { - w.CurrentProject().closeSelectedTask() - w.SetItemCount(len(w.CurrentProject().tasks)) +func (widget *Widget) Close() { + widget.CurrentProject().closeSelectedTask() + widget.SetItemCount(len(widget.CurrentProject().tasks)) - if w.CurrentProject().isLast() { - w.Prev() + if widget.CurrentProject().isLast() { + widget.Prev() return } - w.CurrentProject().index = w.Selected - w.RenderFunction() + widget.CurrentProject().index = widget.Selected + widget.RenderFunction() } // Delete deletes the currently-selected task in the currently-selected project -func (w *Widget) Delete() { - w.CurrentProject().deleteSelectedTask() - w.SetItemCount(len(w.CurrentProject().tasks)) +func (widget *Widget) Delete() { + widget.CurrentProject().deleteSelectedTask() + widget.SetItemCount(len(widget.CurrentProject().tasks)) - if w.CurrentProject().isLast() { - w.Prev() + if widget.CurrentProject().isLast() { + widget.Prev() } - w.CurrentProject().index = w.Selected - w.RenderFunction() + widget.CurrentProject().index = widget.Selected + widget.RenderFunction() } /* -------------------- Unexported Functions -------------------- */ @@ -136,7 +136,7 @@ func (widget *Widget) loadProjects() { projects := []*Project{} for _, id := range widget.settings.projects { - proj := NewProject(id.(int)) + proj := NewProject(id) projects = append(projects, proj) }