Skip to content

Commit

Permalink
refactoring assignable
Browse files Browse the repository at this point in the history
  • Loading branch information
skanehira committed Oct 31, 2020
1 parent 2c1fd6c commit c04672f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 38 deletions.
1 change: 1 addition & 0 deletions github/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type AssignableUsers struct {
Nodes []struct {
Login githubv4.String
}
PageInfo PageInfo
}

type Labels struct {
Expand Down
65 changes: 27 additions & 38 deletions ui/assignees.go
Original file line number Diff line number Diff line change
@@ -1,60 +1,49 @@
package ui

import (
"log"

"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"github.com/shurcooL/githubv4"
"github.com/skanehira/ght/config"
"github.com/skanehira/ght/github"
)

type AssignableUsers struct {
type AssignableUser struct {
Login string
}

type AssigneesUI struct {
updater func(f func())
*tview.Table
func (a *AssignableUser) Key() string {
return a.Login
}

func NewAssignableUI(updater func(f func())) *AssigneesUI {
ui := &AssigneesUI{
Table: tview.NewTable().SetSelectable(true, false).Select(0, 0).SetFixed(0, 0),
updater: updater,
}
ui.SetBorder(true).SetTitle("assignabel user list").SetTitleAlign(tview.AlignLeft)
go ui.updateAssignees()
return ui
func (a *AssignableUser) Fields() []string {
return []string{a.Login}
}

func (ui *AssigneesUI) updateAssignees() {
table := ui.Clear()
v := map[string]interface{}{
"owner": githubv4.String(config.GitHub.Owner),
"name": githubv4.String(config.GitHub.Repo),
"first": githubv4.Int(100),
"cursor": (*githubv4.String)(nil),
}
resp, err := github.GetRepoAssignableUsers(v)
if err != nil {
log.Println(err)
return
}
ui.updater(func() {
assignees := make([]AssignableUsers, len(resp.Nodes))
func NewAssignableUI(updater func(f func())) *SelectListUI {
getList := func(cursor *string) ([]ListData, github.PageInfo) {
v := map[string]interface{}{
"owner": githubv4.String(config.GitHub.Owner),
"name": githubv4.String(config.GitHub.Repo),
"first": githubv4.Int(100),
"cursor": (*githubv4.String)(cursor),
}
resp, err := github.GetRepoAssignableUsers(v)
if err != nil {
return nil, github.PageInfo{}
}

assignees := make([]ListData, len(resp.Nodes))
for i, p := range resp.Nodes {
login := string(p.Login)
assignees[i] = AssignableUsers{
Login: login,
assignees[i] = &AssignableUser{
Login: string(p.Login),
}

table.SetCell(i, 0, tview.NewTableCell(login).
SetTextColor(tcell.ColorYellowGreen).SetExpansion(1))
}
return assignees, resp.PageInfo
}

capture := func(event *tcell.EventKey) *tcell.EventKey {
return event
}

ui.ScrollToBeginning()
})
return NewSelectListUI("assibnable user list", updater, tcell.ColorGreen, getList, capture)
}

0 comments on commit c04672f

Please sign in to comment.