From be7b2f24496c550ac5253ca52b2efd2b16a5e0fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wi=C4=99cek?= Date: Tue, 4 Jun 2024 17:11:08 +0200 Subject: [PATCH] fix: add missing list preview logic (#136) --- ui/components/folders-list/component.go | 11 ------ ui/components/folders-list/keys.go | 6 +--- ui/components/lists-list/component.go | 4 --- ui/components/spaces-list/component.go | 11 ------ ui/components/workspaces-list/component.go | 16 --------- ui/views/compact/view.go | 17 ++-------- ui/widgets/navigator/widget.go | 39 ++++++++++++++++------ 7 files changed, 31 insertions(+), 73 deletions(-) diff --git a/ui/components/folders-list/component.go b/ui/components/folders-list/component.go index eb50364..ff01944 100644 --- a/ui/components/folders-list/component.go +++ b/ui/components/folders-list/component.go @@ -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 { diff --git a/ui/components/folders-list/keys.go b/ui/components/folders-list/keys.go index 1a90774..b8c4595 100644 --- a/ui/components/folders-list/keys.go +++ b/ui/components/folders-list/keys.go @@ -1,8 +1,6 @@ package folderslist import ( - "reflect" - "github.com/charmbracelet/bubbles/key" tea "github.com/charmbracelet/bubbletea" "github.com/prgrs/clickup/pkg/clickup" @@ -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() diff --git a/ui/components/lists-list/component.go b/ui/components/lists-list/component.go index 487384f..be12697 100644 --- a/ui/components/lists-list/component.go +++ b/ui/components/lists-list/component.go @@ -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 { diff --git a/ui/components/spaces-list/component.go b/ui/components/spaces-list/component.go index ddaefb0..83b6c33 100644 --- a/ui/components/spaces-list/component.go +++ b/ui/components/spaces-list/component.go @@ -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 { diff --git a/ui/components/workspaces-list/component.go b/ui/components/workspaces-list/component.go index 3a6658c..eb6658d 100644 --- a/ui/components/workspaces-list/component.go +++ b/ui/components/workspaces-list/component.go @@ -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 { diff --git a/ui/views/compact/view.go b/ui/views/compact/view.go index e374be2..48f9bd6 100644 --- a/ui/views/compact/view.go +++ b/ui/views/compact/view.go @@ -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: @@ -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 -// } -// } diff --git a/ui/widgets/navigator/widget.go b/ui/widgets/navigator/widget.go index 29d1136..d809bfc 100644 --- a/ui/widgets/navigator/widget.go +++ b/ui/widgets/navigator/widget.go @@ -2,7 +2,6 @@ package navigator import ( "fmt" - "reflect" "github.com/charmbracelet/bubbles/spinner" tea "github.com/charmbracelet/bubbletea" @@ -108,14 +107,13 @@ 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, @@ -123,6 +121,11 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd { 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) @@ -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...) @@ -141,7 +144,7 @@ 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, @@ -149,9 +152,14 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd { 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...) @@ -161,7 +169,7 @@ 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, @@ -169,9 +177,14 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd { 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...) @@ -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")