From 205306db6175dc3bc9e85b0d10c9b9d2bbf3e06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wi=C4=99cek?= Date: Thu, 23 May 2024 16:13:42 +0200 Subject: [PATCH 1/6] chore: remove unused code --- ui/widgets/navigator/widget.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/ui/widgets/navigator/widget.go b/ui/widgets/navigator/widget.go index f21c91a..d7618f8 100644 --- a/ui/widgets/navigator/widget.go +++ b/ui/widgets/navigator/widget.go @@ -103,16 +103,12 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("Received: Go to previous view") switch m.state { - // case workspaceslist.ComponentId: case spaceslist.ComponentId: m.state = workspaceslist.ComponentId - // cmd = common.WorkspaceChangeCmd(m.componentWorkspacesList.SelectedWorkspace) case folderslist.ComponentId: m.state = spaceslist.ComponentId - // cmd = common.SpaceChangeCmd(m.componentSpacesList.SelectedSpace) case listslist.ComponentId: m.state = folderslist.ComponentId - // cmd = common.FolderChangeCmd(m.componentFoldersList.SelectedFolder) } cmds = append(cmds, cmd) @@ -131,16 +127,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { } cmds = append(cmds, cmd) - switch keypress := msg.String(); keypress { - // case "enter": - // switch m.state { - // case workspaceslist.ComponentId: - // m.state = folderslist.ComponentId - // } - // case "b": - // m.state = workspaceslist.ComponentId - } - return m, tea.Batch(cmds...) case common.WorkspaceChangeMsg: From 8737fcd3117ceee0c4575682a62e005e285eff26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wi=C4=99cek?= Date: Thu, 23 May 2024 16:33:21 +0200 Subject: [PATCH 2/6] chore: remove unused prop --- ui/components/spaces-list/spaces.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/ui/components/spaces-list/spaces.go b/ui/components/spaces-list/spaces.go index 8c15b7d..98fc8bb 100644 --- a/ui/components/spaces-list/spaces.go +++ b/ui/components/spaces-list/spaces.go @@ -14,13 +14,12 @@ import ( const ComponentId = "spacesList" type Model struct { - list list.Model - ctx *context.UserContext - log *log.Logger - ComponentId common.ComponentId - SelectedSpace string - SelectedWorkspace string - spaces []clickup.Space + list list.Model + ctx *context.UserContext + log *log.Logger + ComponentId common.ComponentId + SelectedSpace string + spaces []clickup.Space } func (m Model) KeyMap() help.KeyMap { @@ -132,7 +131,6 @@ func (m *Model) SetSize(s common.Size) { func (m *Model) WorkspaceChanged(id string) error { m.log.Infof("Received: WorkspaceChangeMsg: %s", id) - m.SelectedWorkspace = id spaces, err := m.ctx.Api.GetSpaces(id) if err != nil { From 784b4aadd023fca42ecdbb52dd31a441c7eff43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wi=C4=99cek?= Date: Thu, 23 May 2024 16:33:30 +0200 Subject: [PATCH 3/6] chore: remove comments --- ui/components/views-tabs/viewstabs.go | 61 ------------------- .../workspaces-list/workspaceslist.go | 24 -------- ui/views/compact/compact.go | 1 - 3 files changed, 86 deletions(-) diff --git a/ui/components/views-tabs/viewstabs.go b/ui/components/views-tabs/viewstabs.go index c0577df..d1684cf 100644 --- a/ui/components/views-tabs/viewstabs.go +++ b/ui/components/views-tabs/viewstabs.go @@ -194,67 +194,6 @@ func (m Model) View() string { ) } -// func (m Model) View() string { -// bColor := lipgloss.Color("#FFF") -// if m.Focused { -// bColor = lipgloss.Color("#8909FF") -// } -// -// borderMargin := 0 -// if m.ifBorders { -// borderMargin = 2 -// } -// -// style := lipgloss.NewStyle(). -// BorderStyle(lipgloss.RoundedBorder()). -// BorderForeground(bColor). -// BorderBottom(m.ifBorders). -// BorderRight(m.ifBorders). -// BorderTop(m.ifBorders). -// BorderLeft(m.ifBorders). -// Height(1). -// MaxHeight(1 + borderMargin). -// Width(m.size.Width - borderMargin). -// MaxWidth(m.size.Width + borderMargin) -// -// s := new(strings.Builder) -// s.WriteString(" Views |") -// -// if len(m.tabs) == 0 { -// s.WriteString(" ") -// return style.Render(s.String()) -// } -// m.log.Debugf("Rendering %d tabs", len(m.tabs)) -// -// moreTabsIcon := " + " -// for i, tab := range m.tabs { -// m.log.Debugf("Rendering tab: %s %s", tab.Name, tab.Id) -// // m.EndIdx = i -// -// t := "" -// tabContent := " " + tab.Name + " " -// if m.SelectedTab == tab.Id { -// t = activeTabStyle.Render(tabContent) -// } else { -// t = inactiveTabStyle.Render(tabContent) -// } -// -// content := " " + t + " " -// -// if lipgloss.Width(s.String()+content+moreTabsIcon) >= m.size.Width-borderMargin { -// s.WriteString(moreTabsIcon) -// break -// } -// s.WriteString(content) -// -// if i != len(m.tabs)-1 { -// s.WriteString("|") -// } -// } -// -// return style.Render(s.String()) -// } - func (m Model) Init() tea.Cmd { m.log.Info("Initializing...") return nil diff --git a/ui/components/workspaces-list/workspaceslist.go b/ui/components/workspaces-list/workspaceslist.go index 3207f93..4afc257 100644 --- a/ui/components/workspaces-list/workspaceslist.go +++ b/ui/components/workspaces-list/workspaceslist.go @@ -122,12 +122,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.SelectedWorkspace = selectedWorkspace return m, common.WorkspacePreviewCmd(selectedWorkspace) } - - // switch { - // case key.Matches(msg, m.list.KeyMap.CursorDown): - // m.list.CursorUp() - // return m, nil - // } } m.list, cmd = m.list.Update(msg) @@ -136,28 +130,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { return m, tea.Batch(cmds...) } -// func (m Model) View() string { func (m Model) View() string { return m.list.View() } -// bColor := lipgloss.Color("#FFF") -// if m.Focused { -// bColor = lipgloss.Color("#8909FF") -// } -// -// return lipgloss.NewStyle(). -// BorderStyle(lipgloss.RoundedBorder()). -// BorderForeground(bColor). -// BorderBottom(m.ifBorders). -// BorderRight(m.ifBorders). -// BorderTop(m.ifBorders). -// BorderLeft(m.ifBorders). -// Render( -// m.list.View(), -// ) -// } - func (m Model) Init() tea.Cmd { m.log.Infof("Initializing...") return nil diff --git a/ui/views/compact/compact.go b/ui/views/compact/compact.go index 2dee1d0..a977902 100644 --- a/ui/views/compact/compact.go +++ b/ui/views/compact/compact.go @@ -145,7 +145,6 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) { m.showSpinner = false case spinner.TickMsg: - // m.log.Info("Received: spinner.TickMsg") if m.showSpinner { m.spinner, cmd = m.spinner.Update(msg) cmds = append(cmds, cmd) From cf8e2479acf167405fbbbdd78b55010d1107e6ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wi=C4=99cek?= Date: Sat, 25 May 2024 11:13:43 +0200 Subject: [PATCH 4/6] chore: go tidy --- go.mod | 5 +---- go.sum | 6 ------ 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 2f17845..e42c6f1 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/spf13/pflag v1.0.5 golang.design/x/clipboard v0.7.0 golang.org/x/term v0.18.0 + gopkg.in/yaml.v3 v3.0.1 ) require ( @@ -19,9 +20,7 @@ require ( github.com/dlclark/regexp2 v1.4.0 // indirect github.com/gorilla/css v1.0.0 // indirect github.com/microcosm-cc/bluemonday v1.0.21 // indirect - github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect - github.com/pelletier/go-toml v1.9.3 // indirect github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect github.com/yuin/goldmark v1.5.2 // indirect github.com/yuin/goldmark-emoji v1.0.1 // indirect @@ -30,7 +29,6 @@ require ( golang.org/x/image v0.14.0 // indirect golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a // indirect golang.org/x/net v0.23.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) require ( @@ -39,7 +37,6 @@ require ( github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect github.com/evertras/bubble-table v0.15.5 github.com/go-logfmt/logfmt v0.6.0 // indirect - github.com/kkyr/fig v0.3.2 github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-isatty v0.0.18 // indirect github.com/mattn/go-localereader v0.0.1 // indirect diff --git a/go.sum b/go.sum index 60e5166..2d7b918 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,6 @@ github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= -github.com/kkyr/fig v0.3.2 h1:+vMj52FL6RJUxeKOBB6JXIMyyi1/2j1ERDrZXjoBjzM= -github.com/kkyr/fig v0.3.2/go.mod h1:ItUILF8IIzgZOMhx5xpJ1W/bviQsWRKOwKXfE/tqUoA= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= @@ -48,8 +46,6 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/microcosm-cc/bluemonday v1.0.21 h1:dNH3e4PSyE4vNX+KlRGHT5KrSvjeUkoNPwEORjffHJg= github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM= -github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= -github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34= github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= @@ -61,8 +57,6 @@ github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= -github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= -github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= From f4027cd27229be35fff5d6eaeb3011ac85b533a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wi=C4=99cek?= Date: Sat, 25 May 2024 11:18:21 +0200 Subject: [PATCH 5/6] feat: refactor list-item to hold data and make list components to hold clickup obj --- ui/components/folders-list/folders.go | 49 ++++++++------- ui/components/folders-list/utils.go | 21 ------- ui/components/list-item/item.go | 23 ++------ ui/components/lists-list/lists.go | 57 ++++++++++-------- ui/components/lists-list/utils.go | 21 ------- ui/components/spaces-list/spaces.go | 46 ++++++++------- ui/components/spaces-list/utils.go | 21 ------- ui/components/workspaces-list/utils.go | 21 ------- .../workspaces-list/workspaceslist.go | 59 +++++++++++-------- ui/views/compact/compact.go | 13 ++-- ui/widgets/navigator/widget.go | 10 +++- 11 files changed, 136 insertions(+), 205 deletions(-) delete mode 100644 ui/components/folders-list/utils.go delete mode 100644 ui/components/lists-list/utils.go delete mode 100644 ui/components/spaces-list/utils.go delete mode 100644 ui/components/workspaces-list/utils.go diff --git a/ui/components/folders-list/folders.go b/ui/components/folders-list/folders.go index 783dd67..e7dc217 100644 --- a/ui/components/folders-list/folders.go +++ b/ui/components/folders-list/folders.go @@ -18,8 +18,7 @@ type Model struct { ctx *context.UserContext log *log.Logger ComponentId common.ComponentId - SelectedSpace string - SelectedFolder string + SelectedFolder clickup.Folder folders []clickup.Folder } @@ -44,8 +43,7 @@ func InitialModel(ctx *context.UserContext, logger *log.Logger) Model { ComponentId: ComponentId, list: l, ctx: ctx, - SelectedFolder: "", - SelectedSpace: ctx.Config.DefaultSpace, + SelectedFolder: clickup.Folder{}, folders: []clickup.Folder{}, log: log, } @@ -55,18 +53,18 @@ func (m *Model) syncList(folders []clickup.Folder) { m.log.Info("Synchronizing list") m.folders = folders - sre_index := 0 - items := folderListToItems(folders) - itemsList := listitem.ItemListToBubblesItems(items) + items := NewListItem(folders) - for i, item := range items { - if item.Description() == m.ctx.Config.DefaultFolder { - sre_index = i + for _, item := range items { + i := item.(listitem.Item) + if i.Title() == m.ctx.Config.DefaultFolder { + m.SelectedFolder = i.Data().(clickup.Folder) } } - m.list.SetItems(itemsList) - m.list.Select(sre_index) + m.list.SetItems(items) + m.list.Select(0) + m.log.Info("List synchronized") } func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { @@ -81,10 +79,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("List is empty") break } - selectedFolder := listitem.BubblesItemToItem(m.list.SelectedItem()).Description() - m.log.Infof("Selected folder %s", selectedFolder) + selectedFolder := m.list.SelectedItem().(listitem.Item).Data().(clickup.Folder) + m.log.Info("Selected folder", "id", selectedFolder.Id, "name", selectedFolder.Name) m.SelectedFolder = selectedFolder - return m, FolderChangeCmd(selectedFolder) + return m, FolderChangeCmd(selectedFolder.Id) case "J", "shift+down": m.list.CursorDown() @@ -92,10 +90,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("List is empty") break } - selectedFolder := listitem.BubblesItemToItem(m.list.SelectedItem()).Description() - m.log.Infof("Selected folder %s", selectedFolder) + selectedFolder := m.list.SelectedItem().(listitem.Item).Data().(clickup.Folder) + m.log.Info("Selected folder", "id", selectedFolder.Id, "name", selectedFolder.Name) m.SelectedFolder = selectedFolder - return m, common.FolderPreviewCmd(selectedFolder) + return m, common.FolderPreviewCmd(selectedFolder.Id) case "K", "shift+up": m.list.CursorUp() @@ -103,10 +101,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("List is empty") break } - selectedFolder := listitem.BubblesItemToItem(m.list.SelectedItem()).Description() - m.log.Infof("Selected folder %s", selectedFolder) + selectedFolder := m.list.SelectedItem().(listitem.Item).Data().(clickup.Folder) + m.log.Info("Selected folder", "id", selectedFolder.Id, "name", selectedFolder.Name) m.SelectedFolder = selectedFolder - return m, common.FolderPreviewCmd(selectedFolder) + return m, common.FolderPreviewCmd(selectedFolder.Id) } } @@ -131,7 +129,6 @@ func (m *Model) SetSize(s common.Size) { func (m *Model) SpaceChanged(id string) error { m.log.Infof("Received: SpaceChangedMsg: %s", id) - m.SelectedSpace = id folders, err := m.ctx.Api.GetFolders(id) if err != nil { @@ -141,3 +138,11 @@ func (m *Model) SpaceChanged(id string) error { m.syncList(folders) return nil } + +func NewListItem(items []clickup.Folder) []list.Item { + result := make([]list.Item, len(items)) + for i, v := range items { + result[i] = listitem.NewItem(v.Name, v.Id, v) + } + return result +} diff --git a/ui/components/folders-list/utils.go b/ui/components/folders-list/utils.go deleted file mode 100644 index 23ae517..0000000 --- a/ui/components/folders-list/utils.go +++ /dev/null @@ -1,21 +0,0 @@ -package folderslist - -import ( - "github.com/prgrs/clickup/pkg/clickup" - listitem "github.com/prgrs/clickup/ui/components/list-item" -) - -func folderListToItems(folders []clickup.Folder) []listitem.Item { - items := make([]listitem.Item, len(folders)) - for i, folder := range folders { - items[i] = folderToItem(folder) - } - return items -} - -func folderToItem(folder clickup.Folder) listitem.Item { - return listitem.NewItem( - folder.Name, - folder.Id, - ) -} diff --git a/ui/components/list-item/item.go b/ui/components/list-item/item.go index 6c65f97..179ec6a 100644 --- a/ui/components/list-item/item.go +++ b/ui/components/list-item/item.go @@ -1,35 +1,20 @@ package listitem -import "github.com/charmbracelet/bubbles/list" - type Item struct { title string desc string + data interface{} } -func NewItem(title, desc string) Item { +func NewItem(title, desc string, data interface{}) Item { return Item{ title: title, desc: desc, + data: data, } } func (i Item) Title() string { return i.title } func (i Item) Description() string { return i.desc } func (i Item) FilterValue() string { return i.title } - -func ItemListToBubblesItems(items []Item) []list.Item { - listItems := make([]list.Item, len(items)) - for i, item := range items { - listItems[i] = ItemToBubblesItem(item) - } - return listItems -} - -func ItemToBubblesItem(item Item) list.Item { - return list.Item(item) -} - -func BubblesItemToItem(item list.Item) Item { - return item.(Item) -} +func (i Item) Data() interface{} { return i.data } diff --git a/ui/components/lists-list/lists.go b/ui/components/lists-list/lists.go index c24028e..344d8d9 100644 --- a/ui/components/lists-list/lists.go +++ b/ui/components/lists-list/lists.go @@ -14,13 +14,12 @@ import ( const ComponentId = "viewLists" type Model struct { - list list.Model - ctx *context.UserContext - log *log.Logger - ComponentId common.ComponentId - SelectedList string - SelectedFolder string - lists []clickup.List + list list.Model + ctx *context.UserContext + log *log.Logger + ComponentId common.ComponentId + SelectedList clickup.List + lists []clickup.List } func InitialModel(ctx *context.UserContext, logger *log.Logger) Model { @@ -34,13 +33,12 @@ func InitialModel(ctx *context.UserContext, logger *log.Logger) Model { log := logger.WithPrefix(logger.GetPrefix() + "/" + ComponentId) return Model{ - ComponentId: ComponentId, - list: l, - ctx: ctx, - SelectedFolder: "", - SelectedList: "", - lists: []clickup.List{}, - log: log, + ComponentId: ComponentId, + list: l, + ctx: ctx, + SelectedList: clickup.List{}, + lists: []clickup.List{}, + log: log, } } @@ -55,10 +53,9 @@ func (m *Model) syncList(lists []clickup.List) { m.log.Info("Synchronizing list") m.lists = lists - items := listsListToItems(lists) - itemsList := listitem.ItemListToBubblesItems(items) + items := NewListItem(lists) - m.list.SetItems(itemsList) + m.list.SetItems(items) m.list.Select(0) m.log.Info("List synchronized") } @@ -75,10 +72,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("List is empty") break } - selectedList := listitem.BubblesItemToItem(m.list.SelectedItem()).Description() - m.log.Infof("Selected list %s", selectedList) + selectedList := m.list.SelectedItem().(listitem.Item).Data().(clickup.List) + m.log.Info("Selected list", "id", selectedList.Id, "name", selectedList.Name) m.SelectedList = selectedList - return m, ListChangedCmd(m.SelectedList) + return m, ListChangedCmd(m.SelectedList.Id) case "J", "shift+down": m.list.CursorDown() @@ -86,10 +83,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("List is empty") break } - selectedList := listitem.BubblesItemToItem(m.list.SelectedItem()).Description() - m.log.Infof("Selected list %s", selectedList) + selectedList := m.list.SelectedItem().(listitem.Item).Data().(clickup.List) + m.log.Info("Selected list", "id", selectedList.Id, "name", selectedList.Name) m.SelectedList = selectedList - return m, common.ListPreviewCmd(m.SelectedList) + return m, common.ListPreviewCmd(m.SelectedList.Id) case "K", "shift+up": m.list.CursorUp() @@ -97,10 +94,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("List is empty") break } - selectedList := listitem.BubblesItemToItem(m.list.SelectedItem()).Description() - m.log.Infof("Selected list %s", selectedList) + selectedList := m.list.SelectedItem().(listitem.Item).Data().(clickup.List) + m.log.Info("Selected list", "id", selectedList.Id, "name", selectedList.Name) m.SelectedList = selectedList - return m, common.ListPreviewCmd(m.SelectedList) + return m, common.ListPreviewCmd(m.SelectedList.Id) } } @@ -132,3 +129,11 @@ func (m *Model) SpaceChanged(id string) error { return nil } + +func NewListItem(items []clickup.List) []list.Item { + result := make([]list.Item, len(items)) + for i, v := range items { + result[i] = listitem.NewItem(v.Name, v.Id, v) + } + return result +} diff --git a/ui/components/lists-list/utils.go b/ui/components/lists-list/utils.go deleted file mode 100644 index 311c29a..0000000 --- a/ui/components/lists-list/utils.go +++ /dev/null @@ -1,21 +0,0 @@ -package listslist - -import ( - "github.com/prgrs/clickup/pkg/clickup" - listitem "github.com/prgrs/clickup/ui/components/list-item" -) - -func listsListToItems(lists []clickup.List) []listitem.Item { - items := make([]listitem.Item, len(lists)) - for i, list := range lists { - items[i] = listToItem(list) - } - return items -} - -func listToItem(list clickup.List) listitem.Item { - return listitem.NewItem( - list.Name, - list.Id, - ) -} diff --git a/ui/components/spaces-list/spaces.go b/ui/components/spaces-list/spaces.go index 98fc8bb..4f09b01 100644 --- a/ui/components/spaces-list/spaces.go +++ b/ui/components/spaces-list/spaces.go @@ -18,7 +18,7 @@ type Model struct { ctx *context.UserContext log *log.Logger ComponentId common.ComponentId - SelectedSpace string + SelectedSpace clickup.Space spaces []clickup.Space } @@ -43,7 +43,7 @@ func InitialModel(ctx *context.UserContext, logger *log.Logger) Model { ComponentId: ComponentId, list: l, ctx: ctx, - SelectedSpace: "", + SelectedSpace: clickup.Space{}, spaces: []clickup.Space{}, log: log, } @@ -53,19 +53,17 @@ func (m *Model) syncList(spaces []clickup.Space) { m.log.Info("Synchronizing list...") m.spaces = spaces - sre_index := 0 // TODO: rename - items := spaceListToItems(spaces) - itemsList := listitem.ItemListToBubblesItems(items) + items := NewListItem(spaces) - for i, item := range items { - if item.Description() == m.ctx.Config.DefaultSpace { - sre_index = i + for _, item := range items { + i := item.(listitem.Item) + if i.Title() == m.ctx.Config.DefaultSpace { + m.SelectedSpace = i.Data().(clickup.Space) } } - m.list.SetItems(itemsList) - m.list.Select(sre_index) - + m.list.SetItems(items) + m.list.Select(0) m.log.Info("List synchronized") } @@ -81,10 +79,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("List is empty") break } - selectedSpace := listitem.BubblesItemToItem(m.list.SelectedItem()).Description() - m.log.Infof("Selected space %s", selectedSpace) + selectedSpace := m.list.SelectedItem().(listitem.Item).Data().(clickup.Space) + m.log.Info("Selected space", "id", selectedSpace.Id, "name", selectedSpace.Name) m.SelectedSpace = selectedSpace - return m, SpaceChangedCmd(selectedSpace) + return m, SpaceChangedCmd(selectedSpace.Id) case "J", "shift+down": m.list.CursorDown() @@ -92,10 +90,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("List is empty") break } - selectedSpace := listitem.BubblesItemToItem(m.list.SelectedItem()).Description() - m.log.Info("Selected space", "space", selectedSpace) + selectedSpace := m.list.SelectedItem().(listitem.Item).Data().(clickup.Space) + m.log.Info("Selected space", "id", selectedSpace.Id, "name", selectedSpace.Name) m.SelectedSpace = selectedSpace - return m, common.SpacePreviewCmd(selectedSpace) + return m, common.SpacePreviewCmd(selectedSpace.Id) case "K", "shift+up": m.list.CursorUp() @@ -103,10 +101,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("List is empty") break } - selectedSpace := listitem.BubblesItemToItem(m.list.SelectedItem()).Description() - m.log.Info("Selected space", "space", selectedSpace) + selectedSpace := m.list.SelectedItem().(listitem.Item).Data().(clickup.Space) + m.log.Info("Selected space", "id", selectedSpace.Id, "name", selectedSpace.Name) m.SelectedSpace = selectedSpace - return m, common.SpacePreviewCmd(selectedSpace) + return m, common.SpacePreviewCmd(selectedSpace.Id) } } @@ -140,3 +138,11 @@ func (m *Model) WorkspaceChanged(id string) error { m.syncList(spaces) return nil } + +func NewListItem(items []clickup.Space) []list.Item { + result := make([]list.Item, len(items)) + for i, v := range items { + result[i] = listitem.NewItem(v.Name, v.Id, v) + } + return result +} diff --git a/ui/components/spaces-list/utils.go b/ui/components/spaces-list/utils.go deleted file mode 100644 index adbf7e6..0000000 --- a/ui/components/spaces-list/utils.go +++ /dev/null @@ -1,21 +0,0 @@ -package spaceslist - -import ( - "github.com/prgrs/clickup/pkg/clickup" - listitem "github.com/prgrs/clickup/ui/components/list-item" -) - -func spaceListToItems(spaces []clickup.Space) []listitem.Item { - items := make([]listitem.Item, len(spaces)) - for i, space := range spaces { - items[i] = spaceToItem(space) - } - return items -} - -func spaceToItem(space clickup.Space) listitem.Item { - return listitem.NewItem( - space.Name, - space.Id, - ) -} diff --git a/ui/components/workspaces-list/utils.go b/ui/components/workspaces-list/utils.go deleted file mode 100644 index 1376a3f..0000000 --- a/ui/components/workspaces-list/utils.go +++ /dev/null @@ -1,21 +0,0 @@ -package workspaceslist - -import ( - "github.com/prgrs/clickup/pkg/clickup" - listitem "github.com/prgrs/clickup/ui/components/list-item" -) - -func workspaceListToItems(workspaces []clickup.Team) []listitem.Item { - items := make([]listitem.Item, len(workspaces)) - for i, workspace := range workspaces { - items[i] = workspaceToItem(workspace) - } - return items -} - -func workspaceToItem(workspace clickup.Team) listitem.Item { - return listitem.NewItem( - workspace.Name, - workspace.Id, - ) -} diff --git a/ui/components/workspaces-list/workspaceslist.go b/ui/components/workspaces-list/workspaceslist.go index 4afc257..3964998 100644 --- a/ui/components/workspaces-list/workspaceslist.go +++ b/ui/components/workspaces-list/workspaceslist.go @@ -18,16 +18,12 @@ type Model struct { ctx *context.UserContext log *log.Logger ComponentId common.ComponentId - SelectedWorkspace string + SelectedWorkspace clickup.Workspace workspaces []clickup.Workspace ifBorders bool Focused bool } -func (m Model) GetFocused() bool { - return m.Focused -} - func (m Model) SetFocused(f bool) Model { m.Focused = f return m @@ -41,9 +37,12 @@ func (m Model) KeyMap() help.KeyMap { } func InitialModel(ctx *context.UserContext, logger *log.Logger) Model { - l := list.New([]list.Item{}, + l := list.New( + []list.Item{}, list.NewDefaultDelegate(), - 0, 0) + 0, 0, + ) + l.KeyMap.Quit.Unbind() l.SetShowHelp(false) l.Title = "Workspaces" @@ -54,7 +53,7 @@ func InitialModel(ctx *context.UserContext, logger *log.Logger) Model { ComponentId: ComponentId, list: l, ctx: ctx, - SelectedWorkspace: "", + SelectedWorkspace: clickup.Workspace{}, workspaces: []clickup.Workspace{}, log: log, ifBorders: true, @@ -66,20 +65,22 @@ func (m *Model) syncList(workspaces []clickup.Workspace) { m.log.Info("Synchronizing list...") m.workspaces = workspaces - items := workspaceListToItems(workspaces) - itemsList := listitem.ItemListToBubblesItems(items) + items := NewListItem(workspaces) if len(items) == 0 { panic("list is empty") } - for _, item := range items { - if item.Description() == m.ctx.Config.DefaultWorkspace { - m.SelectedWorkspace = item.Description() + index := 0 + for i, item := range items { + it := item.(listitem.Item) + if it.Title() == m.ctx.Config.DefaultWorkspace { + index = i } } - m.list.SetItems(itemsList) - m.list.Select(0) + m.SelectedWorkspace = items[index].(listitem.Item).Data().(clickup.Workspace) + m.list.SetItems(items) + m.list.Select(index) m.log.Info("List synchronized") } @@ -95,10 +96,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("List is empty") break } - selectedWorkspace := listitem.BubblesItemToItem(m.list.SelectedItem()).Description() - m.log.Info("Selected workspace", "workspace", selectedWorkspace) + selectedWorkspace := m.list.SelectedItem().(listitem.Item).Data().(clickup.Workspace) + m.log.Info("Selected workspace", "id", selectedWorkspace.Id, "name", selectedWorkspace.Name) m.SelectedWorkspace = selectedWorkspace - return m, common.WorkspaceChangeCmd(selectedWorkspace) + return m, common.WorkspaceChangeCmd(selectedWorkspace.Id) case "J", "shift+down": m.list.CursorDown() @@ -106,10 +107,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("List is empty") break } - selectedWorkspace := listitem.BubblesItemToItem(m.list.SelectedItem()).Description() - m.log.Info("Selected workspace", "workspace", selectedWorkspace) + selectedWorkspace := m.list.SelectedItem().(listitem.Item).Data().(clickup.Workspace) + m.log.Info("Selected workspace", "id", selectedWorkspace.Id, "name", selectedWorkspace.Name) m.SelectedWorkspace = selectedWorkspace - return m, common.WorkspacePreviewCmd(selectedWorkspace) + return m, common.WorkspacePreviewCmd(selectedWorkspace.Id) case "K", "shift+up": m.list.CursorUp() @@ -117,10 +118,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.log.Info("List is empty") break } - selectedWorkspace := listitem.BubblesItemToItem(m.list.SelectedItem()).Description() - m.log.Info("Selected workspace", "workspace", selectedWorkspace) + selectedWorkspace := m.list.SelectedItem().(listitem.Item).Data().(clickup.Workspace) + m.log.Info("Selected workspace", "id", selectedWorkspace.Id, "name", selectedWorkspace.Name) m.SelectedWorkspace = selectedWorkspace - return m, common.WorkspacePreviewCmd(selectedWorkspace) + return m, common.WorkspacePreviewCmd(selectedWorkspace.Id) } } @@ -150,8 +151,16 @@ func (m *Model) InitWorkspaces() error { return err } - m.SelectedWorkspace = workspaces[0].Id + m.SelectedWorkspace = workspaces[0] m.syncList(workspaces) return nil } + +func NewListItem(items []clickup.Workspace) []list.Item { + result := make([]list.Item, len(items)) + for i, v := range items { + result[i] = listitem.NewItem(v.Name, v.Id, v) + } + return result +} diff --git a/ui/views/compact/compact.go b/ui/views/compact/compact.go index a977902..8fb55d0 100644 --- a/ui/views/compact/compact.go +++ b/ui/views/compact/compact.go @@ -111,6 +111,7 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) { return m, tea.Batch(cmds...) case InitCompactMsg: + m.showSpinner = false m.log.Info("Received: InitCompactMsg") if err := m.widgetNavigator.Init(); err != nil { @@ -119,9 +120,10 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) { } initWorkspace := m.widgetNavigator.GetWorkspace() - cmds = append(cmds, common.WorkspacePreviewCmd(initWorkspace)) + m.widgetNavigator.SetWorksapce(initWorkspace) + cmds = append(cmds, common.WorkspacePreviewCmd(initWorkspace.Id)) - views, err := m.ctx.Api.GetViewsFromWorkspace(initWorkspace) + views, err := m.ctx.Api.GetViewsFromWorkspace(initWorkspace.Id) if err != nil { cmds = append(cmds, common.ErrCmd(err)) return m, tea.Batch(cmds...) @@ -133,7 +135,6 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) { } else { tabs := viewsToTabs(views) m.widgetViewsTabs.SetTabs(tabs) - initTab := m.widgetViewsTabs.SelectedTab if err := m.reloadTasks(initTab); err != nil { @@ -142,8 +143,6 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) { } } - m.showSpinner = false - case spinner.TickMsg: if m.showSpinner { m.spinner, cmd = m.spinner.Update(msg) @@ -227,10 +226,10 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) { m.widgetNavigator = m.widgetNavigator.SetFocused(true) } - m.widgetViewsTabs, cmd = m.widgetViewsTabs.Update(msg) + m.widgetNavigator, cmd = m.widgetNavigator.Update(msg) cmds = append(cmds, cmd) - m.widgetNavigator, cmd = m.widgetNavigator.Update(msg) + m.widgetViewsTabs, cmd = m.widgetViewsTabs.Update(msg) cmds = append(cmds, cmd) m.widgetTasks, cmd = m.widgetTasks.Update(msg) diff --git a/ui/widgets/navigator/widget.go b/ui/widgets/navigator/widget.go index d7618f8..ebcdaf8 100644 --- a/ui/widgets/navigator/widget.go +++ b/ui/widgets/navigator/widget.go @@ -8,6 +8,7 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/log" + "github.com/prgrs/clickup/pkg/clickup" "github.com/prgrs/clickup/ui/common" folderslist "github.com/prgrs/clickup/ui/components/folders-list" listslist "github.com/prgrs/clickup/ui/components/lists-list" @@ -38,6 +39,11 @@ type Model struct { componentListsList listslist.Model } +// TODO: refactor +func (m *Model) SetWorksapce(workspace clickup.Workspace) { + m.componentWorkspacesList.SelectedWorkspace = workspace +} + func InitialModel(ctx *context.UserContext, logger *log.Logger) Model { s := spinner.New() s.Spinner = spinner.Pulse @@ -125,8 +131,8 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { case listslist.ComponentId: m.componentListsList, cmd = m.componentListsList.Update(msg) } - cmds = append(cmds, cmd) + cmds = append(cmds, cmd) return m, tea.Batch(cmds...) case common.WorkspaceChangeMsg: @@ -281,7 +287,7 @@ func (m *Model) SetSize(s common.Size) { m.size = s } -func (m Model) GetWorkspace() string { +func (m Model) GetWorkspace() clickup.Workspace { return m.componentWorkspacesList.SelectedWorkspace } From 71a545e44639a89b9674f55b04e25f77722debee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Wi=C4=99cek?= Date: Sat, 25 May 2024 11:18:43 +0200 Subject: [PATCH 6/6] feat: add current path --- ui/components/views-tabs/viewstabs.go | 76 ++++++++++++--------------- ui/views/compact/compact.go | 5 ++ ui/widgets/navigator/widget.go | 18 +++++++ 3 files changed, 57 insertions(+), 42 deletions(-) diff --git a/ui/components/views-tabs/viewstabs.go b/ui/components/views-tabs/viewstabs.go index d1684cf..4666059 100644 --- a/ui/components/views-tabs/viewstabs.go +++ b/ui/components/views-tabs/viewstabs.go @@ -20,16 +20,16 @@ type Tab struct { } type Model struct { - ctx *context.UserContext - log *log.Logger - SelectedTab string - keyMap KeyMap - tabs []Tab - size common.Size - Focused bool - Hidden bool - ifBorders bool - + ctx *context.UserContext + log *log.Logger + SelectedTab string + keyMap KeyMap + tabs []Tab + size common.Size + Focused bool + Hidden bool + ifBorders bool + Path string StartIdx int EndIdx int SelectedTabIdx int @@ -64,12 +64,12 @@ func InitialModel(ctx *context.UserContext, logger *log.Logger) Model { log := logger.WithPrefix(logger.GetPrefix() + "/" + WidgetId) return Model{ - ctx: ctx, - tabs: []Tab{}, - log: log, - keyMap: DefaultKeyMap(), - ifBorders: true, - + ctx: ctx, + tabs: []Tab{}, + log: log, + keyMap: DefaultKeyMap(), + ifBorders: true, + Path: "", StartIdx: 0, EndIdx: 0, SelectedTabIdx: 0, @@ -145,52 +145,44 @@ func (m Model) View() string { MaxWidth(m.size.Width + borderMargin) var s []string + + moreTabsIcon := " + " tabPrefix := " Views |" - // s = append(s, " Views |") + suffix := "" - if len(m.tabs) == 0 { - s = append(s, " ") - return style.Render( - tabPrefix + strings.Join(s, ""), - ) + if m.Path != "" { + suffix += " | " + m.Path } - m.log.Debugf("Rendering %d tabs", len(m.tabs)) - - moreTabsIcon := " + " - // selectedTabVisible := false for _, tab := range m.tabs { - // for i, tab := range m.tabs { - m.log.Debugf("Rendering tab: %s %s", tab.Name, tab.Id) - // m.EndIdx = i - t := "" tabContent := " " + tab.Name + " " + + style := inactiveTabStyle if m.SelectedTab == tab.Id { - t = activeTabStyle.Render(tabContent) - // selectedTabVisible = true - } else { - t = inactiveTabStyle.Render(tabContent) + style = activeTabStyle } + t = style.Render(tabContent) content := " " + t + " " - if lipgloss.Width(tabPrefix+strings.Join(s, "")+content+moreTabsIcon) >= m.size.Width-borderMargin { - // if selectedTabVisible { + if lipgloss.Width(tabPrefix+strings.Join(s, "")+content+moreTabsIcon+suffix) >= m.size.Width-borderMargin { s = append(s, moreTabsIcon) break - // } - // s = s[4:] } s = append(s, content) - - // if i != len(m.tabs)-1 { s = append(s, "|") - // } } + content := strings.Join(s, "") + + dividerWidth := m.size.Width - borderMargin - lipgloss.Width(tabPrefix+content+moreTabsIcon+suffix) + if dividerWidth < 0 { + dividerWidth = 0 + } + divider := strings.Repeat(" ", dividerWidth) return style.Render( - tabPrefix + strings.Join(s, ""), + tabPrefix + content + divider + suffix, ) } diff --git a/ui/views/compact/compact.go b/ui/views/compact/compact.go index 8fb55d0..286894e 100644 --- a/ui/views/compact/compact.go +++ b/ui/views/compact/compact.go @@ -75,6 +75,8 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) { var cmd tea.Cmd var cmds []tea.Cmd + m.widgetViewsTabs.Path = m.widgetNavigator.GetPath() + switch msg := msg.(type) { case tea.KeyMsg: switch keypress := msg.String(); keypress { @@ -107,6 +109,8 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) { m.widgetTasks, cmd = m.widgetTasks.Update(msg) } + m.widgetViewsTabs.Path = m.widgetNavigator.GetPath() + cmds = append(cmds, cmd) return m, tea.Batch(cmds...) @@ -224,6 +228,7 @@ func (m Model) Update(msg tea.Msg) (common.View, tea.Cmd) { m.widgetTasks = m.widgetTasks.SetFocused(false) m.widgetViewsTabs = m.widgetViewsTabs.SetFocused(false) m.widgetNavigator = m.widgetNavigator.SetFocused(true) + m.widgetViewsTabs.Path = m.widgetNavigator.GetPath() } m.widgetNavigator, cmd = m.widgetNavigator.Update(msg) diff --git a/ui/widgets/navigator/widget.go b/ui/widgets/navigator/widget.go index ebcdaf8..edcf575 100644 --- a/ui/widgets/navigator/widget.go +++ b/ui/widgets/navigator/widget.go @@ -44,6 +44,24 @@ func (m *Model) SetWorksapce(workspace clickup.Workspace) { m.componentWorkspacesList.SelectedWorkspace = workspace } +func (m Model) GetPath() string { + switch m.state { + case workspaceslist.ComponentId: + return "/" + case spaceslist.ComponentId: + return "/" + m.componentWorkspacesList.SelectedWorkspace.Name + case folderslist.ComponentId: + return "/" + m.componentWorkspacesList.SelectedWorkspace.Name + "/" + m.componentSpacesList.SelectedSpace.Name + case listslist.ComponentId: + if m.Focused { + return "/" + m.componentWorkspacesList.SelectedWorkspace.Name + "/" + m.componentSpacesList.SelectedSpace.Name + "/" + m.componentFoldersList.SelectedFolder.Name + } + return "/" + m.componentWorkspacesList.SelectedWorkspace.Name + "/" + m.componentSpacesList.SelectedSpace.Name + "/" + m.componentFoldersList.SelectedFolder.Name + "/" + m.componentListsList.SelectedList.Name + default: + return "" + } +} + func InitialModel(ctx *context.UserContext, logger *log.Logger) Model { s := spinner.New() s.Spinner = spinner.Pulse