Skip to content

Commit

Permalink
feat: move editmode into tasks widget, add opt for edditing desc, nam…
Browse files Browse the repository at this point in the history
…e and status (#121)
  • Loading branch information
prgres authored May 31, 2024
1 parent 62c4225 commit 8274ca2
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 82 deletions.
8 changes: 4 additions & 4 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (m *Api) GetTasksFromList(listId string) ([]clickup.Task, error) {
return m.getTasksFromList(true, listId)
}

func (m *Api) syncTasksFromList(listId string) ([]clickup.Task, error) {
func (m *Api) SyncTasksFromList(listId string) ([]clickup.Task, error) {
return m.getTasksFromList(false, listId)
}

Expand All @@ -230,7 +230,7 @@ func (m *Api) GetTasksFromView(viewId string) ([]clickup.Task, error) {
return m.getTasksFromView(true, viewId)
}

func (m *Api) syncTasksFromView(viewId string) ([]clickup.Task, error) {
func (m *Api) SyncTasksFromView(viewId string) ([]clickup.Task, error) {
return m.getTasksFromView(false, viewId)
}

Expand Down Expand Up @@ -430,9 +430,9 @@ func (m *Api) Sync() error {
case CacheNamespaceViewsList:
_, err = m.syncViewsFromList(key)
case CacheNamespaceTasksList:
_, err = m.syncTasksFromList(key)
_, err = m.SyncTasksFromList(key)
case CacheNamespaceTasksView:
_, err = m.syncTasksFromView(key)
_, err = m.SyncTasksFromView(key)
case CacheNamespaceTasks:
_, err = m.SyncTask(key)
default:
Expand Down
11 changes: 7 additions & 4 deletions pkg/clickup/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ type TaskSpace struct {
}

func (t Task) GetAssignees() string {
assignees := []string{}
for _, assignee := range t.Assignees {
assignees = append(assignees, assignee.Username)
assignees := strings.Builder{}
for i := range t.Assignees {
assignees.WriteString(t.Assignees[i].Username)
if i != len(t.Assignees) {
assignees.WriteString(", ")
}
}
return strings.Join(assignees, ",")
return assignees.String()
}

type Assignee struct {
Expand Down
7 changes: 4 additions & 3 deletions ui/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ func OpenUrlInWebBrowser(url string) error {
}

type EditorFinishedMsg struct {
Id string
Data interface{}
Err error
}

func OpenEditor(data string) tea.Cmd {
func OpenEditor(id string, data string) tea.Cmd {
editor := os.Getenv("EDITOR")
if editor == "" {
editor = "vim"
Expand All @@ -49,10 +50,10 @@ func OpenEditor(data string) tea.Cmd {
}

updatedData, err := os.ReadFile(tmpfileName)
data = string(updatedData)

return EditorFinishedMsg{
Data: data,
Id: id,
Data: string(updatedData),
Err: err,
}
})
Expand Down
11 changes: 9 additions & 2 deletions ui/components/table-tasks/taskstable.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (m *Model) setTableSize(s common.Size) {

type KeyMap struct {
table.KeyMap
Select key.Binding
}

func (m Model) KeyMap() KeyMap {
Expand All @@ -104,6 +105,10 @@ func DefaultKeyMap() KeyMap {
ScrollRight: common.KeyBindingWithHelp(km.ScrollRight, "scroll right"),
ScrollLeft: common.KeyBindingWithHelp(km.ScrollLeft, "scroll left"),
},
Select: key.NewBinding(
key.WithKeys("enter"),
key.WithHelp("enter", "select"),
),
}
}

Expand Down Expand Up @@ -132,6 +137,7 @@ func (m Model) Help() help.KeyMap {
{
km.ScrollRight,
km.ScrollLeft,
m.keyMap.Select,
},
}
},
Expand All @@ -142,6 +148,7 @@ func (m Model) Help() help.KeyMap {
km.RowSelectToggle,
km.PageDown,
km.PageUp,
m.keyMap.Select,
}
},
)
Expand Down Expand Up @@ -245,8 +252,8 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {

switch msg := msg.(type) {
case tea.KeyMsg:
switch keypress := msg.String(); keypress {
case "enter":
switch {
case key.Matches(msg, m.keyMap.Select):
index := m.table.GetHighlightedRowIndex()
if m.table.TotalRows() == 0 {
m.log.Info("Table is empty")
Expand Down
53 changes: 3 additions & 50 deletions ui/components/tasks-sidebar/tasksidebar.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func (m Model) Id() common.Id {

type KeyMap struct {
viewport.KeyMap
Edit key.Binding
}

func (m Model) KeyMap() KeyMap {
Expand All @@ -49,10 +48,6 @@ func (m Model) KeyMap() KeyMap {
func DefaultKeyMap() KeyMap {
return KeyMap{
KeyMap: viewport.DefaultKeyMap(),
Edit: key.NewBinding(
key.WithKeys("e"),
key.WithHelp("e", "edit task"),
),
}
}

Expand Down Expand Up @@ -85,9 +80,6 @@ func (m Model) Help() help.KeyMap {
km.HalfPageUp,
km.HalfPageDown,
},
{
km.Edit,
},
}
},
func() []key.Binding {
Expand All @@ -96,7 +88,6 @@ func (m Model) Help() help.KeyMap {
km.Up,
km.PageDown,
km.PageUp,
km.Edit,
}
},
)
Expand Down Expand Up @@ -136,35 +127,6 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
cmds []tea.Cmd
)

switch msg := msg.(type) {
case tea.KeyMsg:
switch {
case key.Matches(msg, m.keyMap.Edit):
data := m.SelectedTask.MarkdownDescription
cmds = append(cmds, common.OpenEditor(data))
}

case common.EditorFinishedMsg:
data := msg.Data.(string)

m.SelectedTask.Description = data
cmds = append(cmds, UpdateTaskCmd(m.SelectedTask))

if err := m.setTask(m.SelectedTask); err != nil {
return common.ErrCmd(err)
}

case UpdateTaskMsg:
t, err := m.ctx.Api.UpdateTask(m.SelectedTask)
if err != nil {
return common.ErrCmd(err)
}

if err := m.setTask(t); err != nil {
return common.ErrCmd(err)
}
}

m.viewport, cmd = m.viewport.Update(msg)
cmds = append(cmds, cmd)

Expand Down Expand Up @@ -246,24 +208,23 @@ func (m Model) WithHidden(h bool) Model {
return m
}

func (m *Model) SetTask(id string) error {
m.log.Infof("Received: TaskSelectedMsg: %s", id)
func (m *Model) SelectTask(id string) error {
m.Ready = false

task, err := m.ctx.Api.GetTask(id)
if err != nil {
return err
}

if err := m.setTask(task); err != nil {
if err := m.SetTask(task); err != nil {
return err
}
m.Ready = true

return nil
}

func (m *Model) setTask(task clickup.Task) error {
func (m *Model) SetTask(task clickup.Task) error {
m.SelectedTask = task
renderedTask, err := m.renderTask(task)
if err != nil {
Expand All @@ -275,11 +236,3 @@ func (m *Model) setTask(task clickup.Task) error {

return nil
}

type UpdateTaskMsg clickup.Task

func UpdateTaskCmd(task clickup.Task) tea.Cmd {
return func() tea.Msg {
return UpdateTaskMsg(task)
}
}
2 changes: 2 additions & 0 deletions ui/theme/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ type Theme struct {
BordersColorActive lipgloss.Color
BordersColorInactive lipgloss.Color
BordersColorCopyMode lipgloss.Color
BordersColorEditMode lipgloss.Color
}

var DefaultTheme = &Theme{
BordersColorActive: lipgloss.Color("#8909FF"),
BordersColorInactive: lipgloss.Color("#FFF"),
BordersColorCopyMode: lipgloss.Color("#e6cc00"),
BordersColorEditMode: lipgloss.Color("#e6cc00"),
}
7 changes: 4 additions & 3 deletions ui/views/compact/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,20 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {

case LoadingTasksFromViewMsg:
id := string(msg)
m.log.Info("Received: LoadingTasksFromViewMsg", "id", id)
m.widgetTasks.SetSpinner(false)

if id == "" {
m.log.Info("Received: LoadingTasksFromViewMsg empty")
m.widgetTasks.SetTasks(nil)
break
}

m.log.Info("Received: LoadingTasksFromViewMsg", "id", id)
if err := m.reloadTasks(id); err != nil {
cmds = append(cmds, common.ErrCmd(err))
return tea.Batch(cmds...)
}

return tea.Batch(cmds...)

case tasks.LostFocusMsg:
m.log.Info("Received: tasks.LostFocusMsg")
m.state = m.widgetNavigator.Id()
Expand Down Expand Up @@ -327,6 +327,7 @@ func (m *Model) reloadTasks(viewId string) error {
return err
}
m.widgetTasks.SetTasks(tasks)
m.widgetTasks.SelectedViewListId = viewId
return nil
}

Expand Down
13 changes: 12 additions & 1 deletion ui/widgets/tasks/commands.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package tasks

import tea "github.com/charmbracelet/bubbletea"
import (
tea "github.com/charmbracelet/bubbletea"
"github.com/prgrs/clickup/pkg/clickup"
)

type LostFocusMsg string

Expand All @@ -9,3 +12,11 @@ func LostFocusCmd() tea.Cmd {
return LostFocusMsg("")
}
}

type UpdateTaskMsg clickup.Task

func UpdateTaskCmd(task clickup.Task) tea.Cmd {
return func() tea.Msg {
return UpdateTaskMsg(task)
}
}
Loading

0 comments on commit 8274ca2

Please sign in to comment.