refactor to use app package instead of service
refactor app to be composable
This commit is contained in:
@@ -6,8 +6,8 @@ import (
|
||||
"io"
|
||||
"sort"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/app"
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/tui/styles"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
type IssueList struct {
|
||||
list list.Model
|
||||
app *service.App
|
||||
app *app.App
|
||||
width int
|
||||
height int
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func renderHeaders(cols []TableColumn) string {
|
||||
return lipgloss.JoinHorizontal(lipgloss.Left, parts...)
|
||||
}
|
||||
|
||||
func NewIssueList(app *service.App, width, height int) IssueList {
|
||||
func NewIssueList(app *app.App, width, height int) IssueList {
|
||||
issues, err := app.Issues.SearchIssues(context.Background(), "", models.IssueFilter{})
|
||||
if err != nil {
|
||||
return IssueList{}
|
||||
@@ -111,7 +111,7 @@ func NewIssueList(app *service.App, width, height int) IssueList {
|
||||
}
|
||||
}
|
||||
|
||||
func NewIssueListFromIssues(app *service.App, issues []*models.Issue, width, height int) IssueList {
|
||||
func NewIssueListFromIssues(app *app.App, issues []*models.Issue, width, height int) IssueList {
|
||||
// for making an IssueList from a pre-existing list of issues.
|
||||
listIssues := make([]list.Item, len(issues))
|
||||
for i, issue := range issues {
|
||||
|
||||
@@ -3,8 +3,8 @@ package dashboard
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/app"
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/charmbracelet/bubbles/textarea"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
@@ -21,7 +21,7 @@ type Model struct {
|
||||
closedIssueList IssueList
|
||||
helpBar HelpBar
|
||||
keyMap DashboardKeyMap
|
||||
app *service.App
|
||||
app *app.App
|
||||
width int
|
||||
height int
|
||||
focusedWindow int // 0 = main (display issues), 1 = closed issues
|
||||
@@ -46,14 +46,14 @@ type Model struct {
|
||||
choosingPriority bool // true while choosing a priority
|
||||
priorityIssueID string
|
||||
choosingType bool // true while choosing a type
|
||||
typeIssueID string
|
||||
feedbackChan chan models.ValidationFeedback
|
||||
quitChan chan bool
|
||||
currentFeedback models.ValidationFeedback
|
||||
showComplete bool
|
||||
typeIssueID string
|
||||
feedbackChan chan models.ValidationFeedback
|
||||
quitChan chan bool
|
||||
currentFeedback models.ValidationFeedback
|
||||
showComplete bool
|
||||
}
|
||||
|
||||
func NewDashboard(app *service.App, feedbackChan chan models.ValidationFeedback, quitChan chan bool) *Model {
|
||||
func NewDashboard(app *app.App, feedbackChan chan models.ValidationFeedback, quitChan chan bool) *Model {
|
||||
m := &Model{
|
||||
header: NewHeader("Project Manager Dashboard"),
|
||||
keyMap: defaultDashboardKeyMap,
|
||||
|
||||
@@ -3,8 +3,8 @@ package dashboard
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/app"
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
@@ -49,7 +49,7 @@ type issueDeletedMsg struct {
|
||||
PreviousIndex int
|
||||
}
|
||||
|
||||
func updateIssueTitleCmd(app *service.App, issueID, newTitle string) tea.Cmd {
|
||||
func updateIssueTitleCmd(app *app.App, issueID, newTitle string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
updates := map[string]interface{}{"title": newTitle}
|
||||
err := app.Issues.UpdateIssue(context.Background(), issueID, updates, "tui")
|
||||
@@ -57,7 +57,7 @@ func updateIssueTitleCmd(app *service.App, issueID, newTitle string) tea.Cmd {
|
||||
}
|
||||
}
|
||||
|
||||
func updateIssueDescriptionCmd(app *service.App, issueID, newDescription string) tea.Cmd {
|
||||
func updateIssueDescriptionCmd(app *app.App, issueID, newDescription string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
updates := map[string]interface{}{"description": newDescription}
|
||||
err := app.Issues.UpdateIssue(context.Background(), issueID, updates, "tui")
|
||||
@@ -65,7 +65,7 @@ func updateIssueDescriptionCmd(app *service.App, issueID, newDescription string)
|
||||
}
|
||||
}
|
||||
|
||||
func updateIssueStatusCmd(app *service.App, issueID, status string) tea.Cmd {
|
||||
func updateIssueStatusCmd(app *app.App, issueID, status string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
updates := map[string]interface{}{"status": status}
|
||||
err := app.Issues.UpdateIssue(context.Background(), issueID, updates, "tui")
|
||||
@@ -73,7 +73,7 @@ func updateIssueStatusCmd(app *service.App, issueID, status string) tea.Cmd {
|
||||
}
|
||||
}
|
||||
|
||||
func updateIssuePriorityCmd(app *service.App, issueID string, priority int) tea.Cmd {
|
||||
func updateIssuePriorityCmd(app *app.App, issueID string, priority int) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
updates := map[string]interface{}{"priority": priority}
|
||||
err := app.Issues.UpdateIssue(context.Background(), issueID, updates, "tui")
|
||||
@@ -81,7 +81,7 @@ func updateIssuePriorityCmd(app *service.App, issueID string, priority int) tea.
|
||||
}
|
||||
}
|
||||
|
||||
func updateIssueTypeCmd(app *service.App, issueID string, issueType models.IssueType) tea.Cmd {
|
||||
func updateIssueTypeCmd(app *app.App, issueID string, issueType models.IssueType) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
updates := map[string]interface{}{"issue_type": string(issueType)}
|
||||
err := app.Issues.UpdateIssue(context.Background(), issueID, updates, "tui")
|
||||
@@ -89,7 +89,7 @@ func updateIssueTypeCmd(app *service.App, issueID string, issueType models.Issue
|
||||
}
|
||||
}
|
||||
|
||||
func createIssueCmd(app *service.App, title string) tea.Cmd {
|
||||
func createIssueCmd(app *app.App, title string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
issue := &models.Issue{
|
||||
Title: title,
|
||||
@@ -102,7 +102,7 @@ func createIssueCmd(app *service.App, title string) tea.Cmd {
|
||||
}
|
||||
}
|
||||
|
||||
func deleteIssueCmd(app *service.App, issueID string, currentIndex int) tea.Cmd {
|
||||
func deleteIssueCmd(app *app.App, issueID string, currentIndex int) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
err := app.Issues.DeleteIssue(context.Background(), issueID)
|
||||
return issueDeletedMsg{IssueID: issueID, Err: err, PreviousIndex: currentIndex}
|
||||
|
||||
Reference in New Issue
Block a user