1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-781 Clean up Todoist project ID handling a bit (#783)

Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
Chris Cummer 2019-12-13 08:51:12 -08:00 committed by GitHub
parent ac18990a8c
commit e1f1d0a410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 18 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/olebedev/config" "github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/utils"
) )
const ( const (
@ -12,19 +13,21 @@ const (
defaultTitle = "Todoist" defaultTitle = "Todoist"
) )
// Settings defines the configuration properties for this module
type Settings struct { type Settings struct {
common *cfg.Common common *cfg.Common
apiKey string apiKey string `help:"Your Todoist API key"`
projects []interface{} projects []int
} }
// NewSettingsFromYAML creates a new settings instance from a YAML config block
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
settings := Settings{ settings := Settings{
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig), common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_TODOIST_TOKEN"))), apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_TODOIST_TOKEN"))),
projects: ymlConfig.UList("projects"), projects: utils.ToInts(ymlConfig.UList("projects")),
} }
return &settings return &settings

View File

@ -102,28 +102,28 @@ func (widget *Widget) Unselect() {
/* -------------------- Keyboard Movement -------------------- */ /* -------------------- Keyboard Movement -------------------- */
// Close closes the currently-selected task in the currently-selected project // Close closes the currently-selected task in the currently-selected project
func (w *Widget) Close() { func (widget *Widget) Close() {
w.CurrentProject().closeSelectedTask() widget.CurrentProject().closeSelectedTask()
w.SetItemCount(len(w.CurrentProject().tasks)) widget.SetItemCount(len(widget.CurrentProject().tasks))
if w.CurrentProject().isLast() { if widget.CurrentProject().isLast() {
w.Prev() widget.Prev()
return return
} }
w.CurrentProject().index = w.Selected widget.CurrentProject().index = widget.Selected
w.RenderFunction() widget.RenderFunction()
} }
// Delete deletes the currently-selected task in the currently-selected project // Delete deletes the currently-selected task in the currently-selected project
func (w *Widget) Delete() { func (widget *Widget) Delete() {
w.CurrentProject().deleteSelectedTask() widget.CurrentProject().deleteSelectedTask()
w.SetItemCount(len(w.CurrentProject().tasks)) widget.SetItemCount(len(widget.CurrentProject().tasks))
if w.CurrentProject().isLast() { if widget.CurrentProject().isLast() {
w.Prev() widget.Prev()
} }
w.CurrentProject().index = w.Selected widget.CurrentProject().index = widget.Selected
w.RenderFunction() widget.RenderFunction()
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
@ -136,7 +136,7 @@ func (widget *Widget) loadProjects() {
projects := []*Project{} projects := []*Project{}
for _, id := range widget.settings.projects { for _, id := range widget.settings.projects {
proj := NewProject(id.(int)) proj := NewProject(id)
projects = append(projects, proj) projects = append(projects, proj)
} }