BNYCTEJNONO7ECZMUSRAMBIZ6H344H2ZGSPAUCTPK2TVFNYPLGYAC
id int64
config *config
data *db.Project
modal tea.Model
err error
loading bool
editing bool
spinner spinner.Model
id int64
config *config
data *db.Project
err error
loadingProject bool
loadingTasks bool
spinner spinner.Model
descVw viewport.Model
taskList table.Model
focus projectViewFocusElement
t := table.New(
table.WithColumns([]table.Column{
{Title: "ID", Width: 4},
{Title: "Name"},
{Title: "Status", Width: 8},
}),
table.WithFocused(true),
)
ts := table.DefaultStyles()
ts.Header = ts.Header.
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(lipgloss.Color("240")).
BorderBottom(true).
Bold(false)
ts.Selected = ts.Selected.
Foreground(lipgloss.Color("229")).
Background(lipgloss.Color("57")).
Bold(false)
t.SetStyles(ts)
m.taskList = t
row, err := m.config.queries.GetProject(context.Background(), m.id)
project, err := m.config.queries.GetProject(context.Background(), m.id)
if err != nil {
return errMsg{err}
}
return project
}
func (m projectModel) fetchTasks() tea.Msg {
tasks, err := m.config.queries.ListTasksByProject(context.Background(), m.id)
case "tab":
switch m.focus {
case focusDesc:
m.focus = focusTasks
m.taskList.Focus()
case focusTasks:
m.focus = focusDesc
m.taskList.Blur()
}
case "enter":
if m.focus == focusTasks {
id, _ := strconv.ParseInt(m.taskList.SelectedRow()[0], 10, 64)
return m, changeView(newTask(m.config, id))
}
if m.editing {
return m.modal.View()
var sb strings.Builder
lg := m.config.lg
titleStyle := lg.NewStyle().
AlignHorizontal(lipgloss.Center).
Width(m.config.getInnerWidth()).
MarginTop(2).
MarginBottom(1).
Bold(true)
title := titleStyle.Render(m.data.Name + "\n")
status := m.config.styles.Base.Render(fmt.Sprintf("Status: %s\n", m.data.Status))
// TODO more task/desc layouts
desc := m.descVw
desc.SetContent(m.data.Description.String)
desc.Width = (m.config.getInnerWidth() / 2) - 4
desc.Height = m.config.getInnerHeight() - lipgloss.Height(title) - lipgloss.Height(status)
cols := m.taskList.Columns()
for i, col := range cols {
if col.Title == "Name" {
col.Width = desc.Width - 4 - 8
cols[i] = col
}
return fmt.Sprintf(
"Name: %s\nDescription:\n%s\nStatus: %s\n",
m.data.Name,
m.data.Description.String,
m.data.Status,
)
descOut := lg.NewStyle().BorderStyle(lipgloss.NormalBorder()).Render(desc.View())
table := lg.NewStyle().BorderStyle(lipgloss.NormalBorder()).Render(m.taskList.View())
sb.WriteString(title)
sb.WriteString(status)
sb.WriteString(lipgloss.JoinHorizontal(lipgloss.Bottom, descOut, table))
return sb.String()