Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Więcek committed Apr 4, 2024
1 parent fc82e74 commit 2689d64
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 42 deletions.
31 changes: 15 additions & 16 deletions ui/components/table-tasks/taskstable.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (m *Model) GetColumnsKey() []string {
}

func (m *Model) refreshTable() tea.Cmd {
m.log.Info("Synchonizing table...")
// m.log.Info("Synchonizing table...")
tasks := m.tasks

m.Hidden = false
Expand All @@ -183,43 +183,39 @@ func (m *Model) refreshTable() tea.Cmd {
// return HideTableCmd()
}

items := taskListToRows(tasks, m.GetColumnsKey())
// items := taskListToRows(tasks, m.GetColumnsKey())

m.log.Infof("!!Table items: %d", len(items))
m.SelectedTaskIndex = m.table.GetHighlightedRowIndex()

pageSize := m.size.Height
m.log.Infof("pageSize: %d", pageSize)
if m.table.GetHeaderVisibility() {
pageSize -= 1
}

if m.table.GetFooterVisibility() {
pageSize -= 1
}

pageSize -= 3 // TODO: why 3? fix
if pageSize < 0 {
pageSize = 1
}

m.log.Infof("WithTargetWidth: %d, WithMaxTotalWidth: %d, WithMinimumHeight: %d, WithPageSize: %d",
m.size.Width,
m.size.Width,
m.size.Height,
pageSize,
)
// m.log.Infof("WithTargetWidth: %d, WithMaxTotalWidth: %d, WithMinimumHeight: %d, WithPageSize: %d",
// m.size.Width,
// m.size.Width,
// m.size.Height,
// pageSize,
// )

m.log.Infof("pageSize: %d", pageSize)
m.table = m.table.
WithRows(items).
// WithRows(items).
WithColumns(m.columns).
WithTargetWidth(m.size.Width).
WithMaxTotalWidth(m.size.Width).
WithMinimumHeight(m.size.Height).
WithPageSize(pageSize)

m.log.Info("Table synchonized")
m.log.Infof("Table size: %v", len(m.table.GetVisibleRows()))

return nil
}

Expand Down Expand Up @@ -340,7 +336,10 @@ func (m Model) TabChanged(tabId string) (Model, tea.Cmd) {

func (m *Model) SetTasks(tasks []clickup.Task) {
m.tasks = tasks
m.refreshTable()
items := taskListToRows(tasks, m.GetColumnsKey())
m.table = m.table.
WithRows(items)
m.log.Info("Table synchonized", "size", len(m.table.GetVisibleRows()))
}

// func (m Model) FetchTasksForView(viewId string) (Model, tea.Cmd) {
Expand Down
56 changes: 30 additions & 26 deletions ui/components/views-tabs/viewstabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@ type Tab struct {
type Model struct {
ctx *context.UserContext
log *log.Logger
SelectedTab string
keyMap KeyMap
tabs []Tab
size common.Size
SelectedTabIdx int
SelectedTab string
Focused bool
Hidden bool
ifBorders bool
}

func (m Model) SetSize(s common.Size) Model {
func (m *Model) SetSize(s common.Size) {
m.size = s

return m
}

func (m Model) KeyMap() help.KeyMap {
Expand Down Expand Up @@ -64,10 +63,11 @@ 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(),
ctx: ctx,
tabs: []Tab{},
log: log,
keyMap: DefaultKeyMap(),
ifBorders: true,
}
}

Expand Down Expand Up @@ -105,12 +105,31 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
}

func (m Model) View() string {
bColor := lipgloss.Color("#FFF")
if m.Focused {
bColor = lipgloss.Color("#8909FF")
}

borderMaring := 0
if m.ifBorders {
borderMaring = 2
}
style := lipgloss.NewStyle().
BorderStyle(lipgloss.RoundedBorder()).
BorderForeground(bColor).
BorderBottom(m.ifBorders).
BorderRight(m.ifBorders).
BorderTop(m.ifBorders).
BorderLeft(m.ifBorders).
// MaxWidth(m.size.Width).
Width(m.size.Width - borderMaring)

s := strings.Builder{}
s.WriteString(" Views |")

if len(m.tabs) == 0 {
s.WriteString(" ")
return s.String()
return style.Render(s.String())
}
m.log.Debugf("Rendering %d tabs", len(m.tabs))

Expand All @@ -130,28 +149,13 @@ func (m Model) View() string {
s.WriteString("|")
}

if s.Len()+len(moreTabsIcon)+2 > m.ctx.WindowSize.Width { // 2 is left and right border
if s.Len()+len(moreTabsIcon) > m.ctx.WindowSize.Width {
s.WriteString(moreTabsIcon)
break
}
}

bColor := lipgloss.Color("#FFF")
if m.Focused {
bColor = lipgloss.Color("#8909FF")
}

return lipgloss.NewStyle().
BorderStyle(lipgloss.RoundedBorder()).
BorderForeground(bColor).
BorderBottom(true).
BorderTop(true).
BorderRight(true).
BorderLeft(true).
MaxWidth(m.ctx.WindowSize.Width).
Render(
s.String(),
)
return style.Render(s.String())
}

func (m Model) Init() tea.Cmd {
Expand Down

0 comments on commit 2689d64

Please sign in to comment.