Skip to content

Commit

Permalink
fix: add missing list preview logic (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
prgres committed Jun 4, 2024
1 parent 5fbe2ec commit be7b2f2
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 73 deletions.
11 changes: 0 additions & 11 deletions ui/components/folders-list/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,8 @@ func InitialModel(ctx *context.UserContext, logger *log.Logger) Model {
func (m *Model) SetList(folders []clickup.Folder) {
m.log.Info("Synchronizing list")
m.folders = folders

items := NewListItem(folders)

for _, item := range items {
i := item.(listitem.Item)
if i.Title() == m.ctx.Config.DefaultFolder {
m.Selected = i.Data().(clickup.Folder)
}
}

m.list.SetItems(items)
m.list.Select(0)
m.log.Info("List synchronized")
}

func (m *Model) Update(msg tea.Msg) tea.Cmd {
Expand Down
6 changes: 1 addition & 5 deletions ui/components/folders-list/keys.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package folderslist

import (
"reflect"

"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/prgrs/clickup/pkg/clickup"
Expand Down Expand Up @@ -54,9 +52,7 @@ func (m *Model) handleKeys(msg tea.KeyMsg) tea.Cmd {
selectedFolder := m.list.SelectedItem().(listitem.Item).Data().(clickup.Folder)
m.log.Info("Selected folder", "id", selectedFolder.Id, "name", selectedFolder.Name)
m.Selected = selectedFolder
tmp := FolderChangedCmd(selectedFolder.Id)
m.log.Debug(tmp, "t", reflect.TypeOf(tmp), "x")
return tmp
return FolderChangedCmd(selectedFolder.Id)

case key.Matches(msg, m.keyMap.CursorUp):
m.list.CursorUp()
Expand Down
4 changes: 0 additions & 4 deletions ui/components/lists-list/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ func (m Model) KeyMap() KeyMap {
func (m *Model) SetList(lists []clickup.List) {
m.log.Info("Synchronizing list")
m.lists = lists

items := NewListItem(lists)

m.list.SetItems(items)
m.list.Select(0)
m.log.Info("List synchronized")
}

func (m *Model) Update(msg tea.Msg) tea.Cmd {
Expand Down
11 changes: 0 additions & 11 deletions ui/components/spaces-list/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,8 @@ func InitialModel(ctx *context.UserContext, logger *log.Logger) Model {
func (m *Model) SetList(spaces []clickup.Space) {
m.log.Info("Synchronizing list...")
m.spaces = spaces

items := NewListItem(spaces)

for _, item := range items {
i := item.(listitem.Item)
if i.Title() == m.ctx.Config.DefaultSpace {
m.Selected = i.Data().(clickup.Space)
}
}

m.list.SetItems(items)
m.list.Select(0)
m.log.Info("List synchronized")
}

func (m *Model) Update(msg tea.Msg) tea.Cmd {
Expand Down
16 changes: 0 additions & 16 deletions ui/components/workspaces-list/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,8 @@ func InitialModel(ctx *context.UserContext, logger *log.Logger) Model {
func (m *Model) SetList(workspaces []clickup.Workspace) {
m.log.Info("Synchronizing list...")
m.workspaces = workspaces

items := NewListItem(workspaces)
if len(items) == 0 {
panic("list is empty")
}

index := 0
for i, item := range items {
it := item.(listitem.Item)
if it.Title() == m.ctx.Config.DefaultWorkspace {
index = i
}
}

m.Selected = items[index].(listitem.Item).Data().(clickup.Workspace)
m.list.SetItems(items)
m.list.Select(index)
m.log.Info("List synchronized")
}

func (m *Model) Update(msg tea.Msg) tea.Cmd {
Expand Down
17 changes: 2 additions & 15 deletions ui/views/compact/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {

case navigator.FolderChangedMsg:
id := string(msg)
m.log.Infof("Received: FolderChangeMsg: %s", id)
m.log.Info("Received: FolderChangeMsg", "id", id)
cmds = append(cmds, m.handleFolderChangePreview(id))

case navigator.ListPreviewMsg:
id := string(msg)
m.log.Infof("Received: ListPreviewMsg: %s", id)
m.log.Info("Received: ListPreviewMsg", "id", id)
cmds = append(cmds, m.handleListChangePreview(id))

case navigator.ListChangedMsg:
Expand Down Expand Up @@ -334,16 +334,3 @@ func (m *Model) handleListChangePreview(id string) tea.Cmd {

return LoadingTasksFromViewCmd(initTab)
}

// func (m *Model) getActiveElement() common.UIElement {
// switch m.state {
// case m.widgetNavigator.Id():
// return m.widgetNavigator
// case m.widgetViewsTabs.Id():
// return m.widgetViewsTabs
// case m.widgetTasks.Id():
// return m.widgetTasks
// default:
// return nil
// }
// }
39 changes: 28 additions & 11 deletions ui/widgets/navigator/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package navigator

import (
"fmt"
"reflect"

"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -108,21 +107,25 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
var cmd tea.Cmd
var cmds []tea.Cmd

m.log.Debug("2222", "t", reflect.TypeOf(msg))
switch msg := msg.(type) {
case tea.KeyMsg:
return m.handleKeys(msg)

case workspaceslist.WorkspaceChangedMsg:
id := string(msg)
m.log.Infof("Received: WorkspaceChangeMsg: %s", id)
m.log.Debug("Received: WorkspaceChangeMsg", "id", id)
m.showSpinner = true
cmds = append(cmds,
m.spinner.Tick,
LoadingSpacesFromWorkspaceCmd(id),
WorkspaceChangedCmd(id),
)

case workspaceslist.WorkspacePreviewMsg:
id := string(msg)
m.log.Debug("Received: workspaceslist.WorkspacePreviewMsg", "id", id)
cmds = append(cmds, WorkspacePreviewCmd(id))

case spinner.TickMsg:
if m.showSpinner {
m.spinner, cmd = m.spinner.Update(msg)
Expand All @@ -131,7 +134,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {

case LoadingSpacesFromWorkspaceMsg:
id := string(msg)
m.log.Infof("Received: LoadingSpacesFromWorkspaceMsg: %s", id)
m.log.Debug("Received: LoadingSpacesFromWorkspaceMsg", "id", id)
if err := m.componentSpacesList.WorkspaceChanged(id); err != nil {
cmds = append(cmds, common.ErrCmd(err))
return tea.Batch(cmds...)
Expand All @@ -141,17 +144,22 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {

case spaceslist.SpaceChangedMsg:
id := string(msg)
m.log.Infof("Received: spaceslist.SpaceChangedMsg: %s", id)
m.log.Debug("Received: spaceslist.SpaceChangedMsg", "id", id)
m.showSpinner = true
cmds = append(cmds,
m.spinner.Tick,
LoadingFoldersFromSpaceCmd(id),
SpaceChangedCmd(id),
)

case spaceslist.SpacePreviewMsg:
id := string(msg)
m.log.Debug("Received: spaceslist.SpacePreviewMsg", "id", id)
cmds = append(cmds, SpacePreviewCmd(id))

case LoadingFoldersFromSpaceMsg:
id := string(msg)
m.log.Infof("Received: LoadingFoldersFromSpaceMsg: %s", id)
m.log.Debug("Received: LoadingFoldersFromSpaceMsg", "id", id)
if err := m.componentFoldersList.SpaceChanged(id); err != nil {
cmds = append(cmds, common.ErrCmd(err))
return tea.Batch(cmds...)
Expand All @@ -161,17 +169,22 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {

case folderslist.FolderChangedMsg:
id := string(msg)
m.log.Infof("Received: FolderChangeMsg: %s", id)
m.log.Debug("Received: folderslist.FolderChangeMsg", "id", id)
m.showSpinner = true
cmds = append(cmds,
m.spinner.Tick,
LoadingListsFromFolderCmd(id),
FolderChangedCmd(id),
)

case folderslist.FolderPreviewMsg:
id := string(msg)
m.log.Debug("Received: folderslist.FolderPreviewMsg", "id", id)
cmds = append(cmds, FolderPreviewCmd(id))

case LoadingListsFromFolderMsg:
id := string(msg)
m.log.Infof("Received: LoadingListsFromFolderMsg: %s", id)
m.log.Debug("Received: LoadingListsFromFolderMsg", "id", id)
if err := m.componentListsList.FolderChanged(id); err != nil {
cmds = append(cmds, common.ErrCmd(err))
return tea.Batch(cmds...)
Expand All @@ -181,9 +194,13 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {

case listslist.ListChangedMsg:
id := string(msg)
m.log.Infof("Received: ListChangedMsg: %s", id)
// m.showSpinner = true
cmds = append(cmds, m.spinner.Tick, ListChangedCmd(id))
m.log.Debug("Received: listslist.ListChangedMsg", "id", id)
cmds = append(cmds, ListChangedCmd(id))

case listslist.ListPreviewMsg:
id := string(msg)
m.log.Debug("Received: listslist.ListPreviewMsg", "id", id)
cmds = append(cmds, ListPreviewCmd(id))

case common.RefreshMsg:
m.log.Debug("Received: common.RefreshMsg")
Expand Down

0 comments on commit be7b2f2

Please sign in to comment.