Skip to content

Commit

Permalink
feat: and fix, prevent double selecting the same (spinner doesnt show…
Browse files Browse the repository at this point in the history
… that often), fixed selecting tabs (#137)
  • Loading branch information
prgres authored Jun 4, 2024
1 parent be7b2f2 commit b09f0ce
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 212 deletions.
10 changes: 8 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const (
CacheNamespaceTasksList cache.Namespace = "tasks-list"
CacheNamespaceTasksView cache.Namespace = "tasks-view"

SyncInterval = 1
SyncInterval = 1000
// SyncInterval = 1
)

type Api struct {
Expand Down Expand Up @@ -465,6 +466,11 @@ func filterViews(views []clickup.View, filters []clickup.ViewType) []clickup.Vie
return result
}

func (m *Api) CheckIfCached(namespace cache.Namespace, key string) bool {
ok, _ := m.getFromCache(namespace, cache.Key(key), nil)
return ok
}

func (m *Api) getFromCache(namespace cache.Namespace, key cache.Key, v interface{}) (bool, error) {
err := m.Cache.Get(namespace, key, v)
if err == nil {
Expand All @@ -475,7 +481,7 @@ func (m *Api) getFromCache(namespace cache.Namespace, key cache.Key, v interface
return false, nil
}

return false, err
return true, err
}

func (m *Api) get(cacheNamespace cache.Namespace, cacheKey cache.Key, data interface{}, fallback func() (interface{}, error), cache bool) error {
Expand Down
3 changes: 2 additions & 1 deletion pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
const (
TTL = 5 * 60
StaleInterval = 15
GarbageCollectorInterval = 1
GarbageCollectorInterval = 1000
// GarbageCollectorInterval = 1
)

var ErrKeyNotFoundInNamespace = errors.New("key not found in namespace")
Expand Down
9 changes: 7 additions & 2 deletions ui/components/folders-list/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package folderslist
import tea "github.com/charmbracelet/bubbletea"

type (
FolderChangedMsg string
FolderPreviewMsg string
FolderChangedMsg string
FolderPreviewMsg string
FolderSelectedMsg string
)

func FolderChangedCmd(id string) tea.Cmd {
Expand All @@ -14,3 +15,7 @@ func FolderChangedCmd(id string) tea.Cmd {
func FolderPreviewCmd(id string) tea.Cmd {
return func() tea.Msg { return FolderPreviewMsg(id) }
}

func FolderSelectedCmd(id string) tea.Cmd {
return func() tea.Msg { return FolderSelectedMsg(id) }
}
33 changes: 21 additions & 12 deletions ui/components/folders-list/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ func (m *Model) handleKeys(msg tea.KeyMsg) tea.Cmd {
m.log.Info("List is empty")
break
}
selectedFolder := m.list.SelectedItem().(listitem.Item).Data().(clickup.Folder)
m.log.Info("Selected folder", "id", selectedFolder.Id, "name", selectedFolder.Name)
m.Selected = selectedFolder
return FolderChangedCmd(selectedFolder.Id)
selected := m.list.SelectedItem().(listitem.Item).Data().(clickup.Folder)
m.log.Info("Selected folder", "id", selected.Id, "name", selected.Name)
if m.Selected.Id == selected.Id {
return FolderSelectedCmd(m.Selected.Id)
}
m.Selected = selected
return FolderChangedCmd(selected.Id)

case key.Matches(msg, m.keyMap.CursorUp):
m.list.CursorUp()
Expand All @@ -63,10 +66,13 @@ func (m *Model) handleKeys(msg tea.KeyMsg) tea.Cmd {
m.log.Info("List is empty")
break
}
selectedFolder := m.list.SelectedItem().(listitem.Item).Data().(clickup.Folder)
m.log.Info("Selected folder", "id", selectedFolder.Id, "name", selectedFolder.Name)
m.Selected = selectedFolder
return FolderPreviewCmd(selectedFolder.Id)
selected := m.list.SelectedItem().(listitem.Item).Data().(clickup.Folder)
m.log.Info("Selected folder", "id", selected.Id, "name", selected.Name)
if m.Selected.Id == selected.Id {
return FolderSelectedCmd(m.Selected.Id)
}
m.Selected = selected
return FolderPreviewCmd(selected.Id)

case key.Matches(msg, m.keyMap.CursorDown):
m.list.CursorDown()
Expand All @@ -77,10 +83,13 @@ func (m *Model) handleKeys(msg tea.KeyMsg) tea.Cmd {
m.log.Info("List is empty")
break
}
selectedFolder := m.list.SelectedItem().(listitem.Item).Data().(clickup.Folder)
m.log.Info("Selected folder", "id", selectedFolder.Id, "name", selectedFolder.Name)
m.Selected = selectedFolder
return FolderPreviewCmd(selectedFolder.Id)
selected := m.list.SelectedItem().(listitem.Item).Data().(clickup.Folder)
m.log.Info("Selected folder", "id", selected.Id, "name", selected.Name)
if m.Selected.Id == selected.Id {
return FolderSelectedCmd(m.Selected.Id)
}
m.Selected = selected
return FolderPreviewCmd(selected.Id)
}

return tea.Batch(cmds...)
Expand Down
17 changes: 9 additions & 8 deletions ui/components/lists-list/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import (
)

type (
ListChangedMsg string
ListPreviewMsg string
ListChangedMsg string
ListPreviewMsg string
ListSelectedMsg string
)

func ListChangedCmd(id string) tea.Cmd {
return func() tea.Msg {
return ListChangedMsg(id)
}
return func() tea.Msg { return ListChangedMsg(id) }
}

func ListPreviewCmd(id string) tea.Cmd {
return func() tea.Msg {
return ListPreviewMsg(id)
}
return func() tea.Msg { return ListPreviewMsg(id) }
}

func ListSelectedCmd(id string) tea.Cmd {
return func() tea.Msg { return ListSelectedMsg(id) }
}
27 changes: 18 additions & 9 deletions ui/components/lists-list/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ func (m *Model) handleKeys(msg tea.KeyMsg) tea.Cmd {
m.log.Info("List is empty")
break
}
selectedList := m.list.SelectedItem().(listitem.Item).Data().(clickup.List)
m.log.Info("Selected list", "id", selectedList.Id, "name", selectedList.Name)
m.Selected = selectedList
selected := m.list.SelectedItem().(listitem.Item).Data().(clickup.List)
m.log.Info("Selected list", "id", selected.Id, "name", selected.Name)
if m.Selected.Id == selected.Id {
return ListSelectedCmd(m.Selected.Id)
}
m.Selected = selected
return ListChangedCmd(m.Selected.Id)

case key.Matches(msg, m.keyMap.CursorDown):
Expand All @@ -61,9 +64,12 @@ func (m *Model) handleKeys(msg tea.KeyMsg) tea.Cmd {
m.log.Info("List is empty")
break
}
selectedList := m.list.SelectedItem().(listitem.Item).Data().(clickup.List)
m.log.Info("Selected list", "id", selectedList.Id, "name", selectedList.Name)
m.Selected = selectedList
selected := m.list.SelectedItem().(listitem.Item).Data().(clickup.List)
m.log.Info("Selected list", "id", selected.Id, "name", selected.Name)
if m.Selected.Id == selected.Id {
return ListSelectedCmd(m.Selected.Id)
}
m.Selected = selected
return ListPreviewCmd(m.Selected.Id)

case key.Matches(msg, m.keyMap.CursorUp):
Expand All @@ -75,9 +81,12 @@ func (m *Model) handleKeys(msg tea.KeyMsg) tea.Cmd {
m.log.Info("List is empty")
break
}
selectedList := m.list.SelectedItem().(listitem.Item).Data().(clickup.List)
m.log.Info("Selected list", "id", selectedList.Id, "name", selectedList.Name)
m.Selected = selectedList
selected := m.list.SelectedItem().(listitem.Item).Data().(clickup.List)
m.log.Info("Selected list", "id", selected.Id, "name", selected.Name)
if m.Selected.Id == selected.Id {
return ListSelectedCmd(m.Selected.Id)
}
m.Selected = selected
return ListPreviewCmd(m.Selected.Id)
}

Expand Down
17 changes: 9 additions & 8 deletions ui/components/spaces-list/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package spaceslist
import tea "github.com/charmbracelet/bubbletea"

type (
SpaceChangedMsg string
SpacePreviewMsg string
SpaceChangedMsg string
SpacePreviewMsg string
SpaceSelectedMsg string
)

func SpaceChangedCmd(id string) tea.Cmd {
return func() tea.Msg {
return SpaceChangedMsg(id)
}
return func() tea.Msg { return SpaceChangedMsg(id) }
}

func SpacePreviewCmd(id string) tea.Cmd {
return func() tea.Msg {
return SpacePreviewMsg(id)
}
return func() tea.Msg { return SpacePreviewMsg(id) }
}

func SpaceSelectedCmd(id string) tea.Cmd {
return func() tea.Msg { return SpaceSelectedMsg(id) }
}
33 changes: 21 additions & 12 deletions ui/components/spaces-list/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ func (m *Model) handleKeys(msg tea.KeyMsg) tea.Cmd {
m.log.Info("List is empty")
break
}
selectedSpace := m.list.SelectedItem().(listitem.Item).Data().(clickup.Space)
m.log.Info("Selected space", "id", selectedSpace.Id, "name", selectedSpace.Name)
m.Selected = selectedSpace
return SpaceChangedCmd(selectedSpace.Id)
selected := m.list.SelectedItem().(listitem.Item).Data().(clickup.Space)
m.log.Info("Selected space", "id", selected.Id, "name", selected.Name)
if m.Selected.Id == selected.Id {
return SpaceSelectedCmd(m.Selected.Id)
}
m.Selected = selected
return SpaceChangedCmd(selected.Id)

case key.Matches(msg, m.keyMap.CursorDown):
m.list.CursorDown()
Expand All @@ -61,10 +64,13 @@ func (m *Model) handleKeys(msg tea.KeyMsg) tea.Cmd {
m.log.Info("List is empty")
break
}
selectedSpace := m.list.SelectedItem().(listitem.Item).Data().(clickup.Space)
m.log.Info("Selected space", "id", selectedSpace.Id, "name", selectedSpace.Name)
m.Selected = selectedSpace
return SpacePreviewCmd(selectedSpace.Id)
selected := m.list.SelectedItem().(listitem.Item).Data().(clickup.Space)
m.log.Info("Selected space", "id", selected.Id, "name", selected.Name)
if m.Selected.Id == selected.Id {
return SpaceSelectedCmd(m.Selected.Id)
}
m.Selected = selected
return SpacePreviewCmd(selected.Id)

case key.Matches(msg, m.keyMap.CursorUp):
m.list.CursorUp()
Expand All @@ -75,10 +81,13 @@ func (m *Model) handleKeys(msg tea.KeyMsg) tea.Cmd {
m.log.Info("List is empty")
break
}
selectedSpace := m.list.SelectedItem().(listitem.Item).Data().(clickup.Space)
m.log.Info("Selected space", "id", selectedSpace.Id, "name", selectedSpace.Name)
m.Selected = selectedSpace
return SpacePreviewCmd(selectedSpace.Id)
selected := m.list.SelectedItem().(listitem.Item).Data().(clickup.Space)
m.log.Info("Selected space", "id", selected.Id, "name", selected.Name)
if m.Selected.Id == selected.Id {
return SpaceSelectedCmd(m.Selected.Id)
}
m.Selected = selected
return SpacePreviewCmd(selected.Id)
}

return nil
Expand Down
12 changes: 3 additions & 9 deletions ui/components/table-tasks/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@ type (
)

func TaskSelectedCmd(task string) tea.Cmd {
return func() tea.Msg {
return TaskSelectedMsg(task)
}
return func() tea.Msg { return TaskSelectedMsg(task) }
}

func TasksListReadyCmd() tea.Cmd {
return func() tea.Msg {
return TasksListReadyMsg(true)
}
return func() tea.Msg { return TasksListReadyMsg(true) }
}

func HideTableCmd() tea.Cmd {
return func() tea.Msg {
return HideTableMsg(true)
}
return func() tea.Msg { return HideTableMsg(true) }
}
11 changes: 7 additions & 4 deletions ui/components/views-tabs/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import (
)

type (
TabChangedMsg string
TabChangedMsg string
TabSelectedMsg string
)

func TabChangedCmd(id string) tea.Cmd {
return func() tea.Msg {
return TabChangedMsg(id)
}
return func() tea.Msg { return TabChangedMsg(id) }
}

func TabSelectedCmd(id string) tea.Cmd {
return func() tea.Msg { return TabSelectedMsg(id) }
}
7 changes: 1 addition & 6 deletions ui/components/views-tabs/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ func (m *Model) handleKeys(msg tea.KeyMsg) tea.Cmd {
return nil

case key.Matches(msg, m.keyMap.Select):
index := nextTab(m.tabs, m.SelectedIdx)
if m.SelectedIdx == index {
break
}
m.SelectedIdx = index
m.Selected = m.tabs[index].Id
m.Selected = m.tabs[m.SelectedIdx].Id
return TabChangedCmd(m.Selected)

case key.Matches(msg, m.keyMap.CursorLeftAndSelect):
Expand Down
17 changes: 9 additions & 8 deletions ui/components/workspaces-list/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package workspaceslist
import tea "github.com/charmbracelet/bubbletea"

type (
WorkspaceChangedMsg string
WorkspacePreviewMsg string
WorkspaceChangedMsg string
WorkspacePreviewMsg string
WorkspaceSelectedMsg string
)

func WorkspaceChangedCmd(id string) tea.Cmd {
return func() tea.Msg {
return WorkspaceChangedMsg(id)
}
return func() tea.Msg { return WorkspaceChangedMsg(id) }
}

func WorkspacePreviewCmd(workspace string) tea.Cmd {
return func() tea.Msg {
return WorkspacePreviewMsg(workspace)
}
return func() tea.Msg { return WorkspacePreviewMsg(workspace) }
}

func WorkspaceSelectedCmd(id string) tea.Cmd {
return func() tea.Msg { return WorkspaceSelectedMsg(id) }
}
1 change: 0 additions & 1 deletion ui/components/workspaces-list/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func (m *Model) InitWorkspaces() error {
return err
}

m.Selected = workspaces[0]
m.SetList(workspaces)

return nil
Expand Down
Loading

0 comments on commit b09f0ce

Please sign in to comment.