Compare commits
1 Commits
feat/task
...
2b31d9bc2b
| Author | SHA1 | Date | |
|---|---|---|---|
| 2b31d9bc2b |
@ -27,10 +27,6 @@ type Styles struct {
|
|||||||
Form *huh.Theme
|
Form *huh.Theme
|
||||||
TableStyle TableStyle
|
TableStyle TableStyle
|
||||||
|
|
||||||
Tab lipgloss.Style
|
|
||||||
ActiveTab lipgloss.Style
|
|
||||||
TabBar lipgloss.Style
|
|
||||||
|
|
||||||
ColumnFocused lipgloss.Style
|
ColumnFocused lipgloss.Style
|
||||||
ColumnBlurred lipgloss.Style
|
ColumnBlurred lipgloss.Style
|
||||||
ColumnInsert lipgloss.Style
|
ColumnInsert lipgloss.Style
|
||||||
@ -75,19 +71,6 @@ func NewStyles(config *taskwarrior.TWConfig) *Styles {
|
|||||||
|
|
||||||
styles.Form = formTheme
|
styles.Form = formTheme
|
||||||
|
|
||||||
styles.Tab = lipgloss.NewStyle().
|
|
||||||
Padding(0, 1).
|
|
||||||
Foreground(lipgloss.Color("240"))
|
|
||||||
|
|
||||||
styles.ActiveTab = styles.Tab.
|
|
||||||
Foreground(lipgloss.Color("252")).
|
|
||||||
Bold(true)
|
|
||||||
|
|
||||||
styles.TabBar = lipgloss.NewStyle().
|
|
||||||
Border(lipgloss.NormalBorder(), false, false, true, false).
|
|
||||||
BorderForeground(lipgloss.Color("240")).
|
|
||||||
MarginBottom(1)
|
|
||||||
|
|
||||||
styles.ColumnFocused = lipgloss.NewStyle().Border(lipgloss.RoundedBorder(), true).Padding(1)
|
styles.ColumnFocused = lipgloss.NewStyle().Border(lipgloss.RoundedBorder(), true).Padding(1)
|
||||||
styles.ColumnBlurred = lipgloss.NewStyle().Border(lipgloss.HiddenBorder(), true).Padding(1)
|
styles.ColumnBlurred = lipgloss.NewStyle().Border(lipgloss.HiddenBorder(), true).Padding(1)
|
||||||
styles.ColumnInsert = lipgloss.NewStyle().Border(lipgloss.RoundedBorder(), true).Padding(1)
|
styles.ColumnInsert = lipgloss.NewStyle().Border(lipgloss.RoundedBorder(), true).Padding(1)
|
||||||
|
|||||||
@ -83,6 +83,12 @@ func (a *Autocomplete) SetMinChars(min int) {
|
|||||||
a.minChars = min
|
a.minChars = min
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSuggestions updates the available suggestions
|
||||||
|
func (a *Autocomplete) SetSuggestions(suggestions []string) {
|
||||||
|
a.allSuggestions = suggestions
|
||||||
|
a.updateFilteredSuggestions()
|
||||||
|
}
|
||||||
|
|
||||||
// Init initializes the autocomplete
|
// Init initializes the autocomplete
|
||||||
func (a *Autocomplete) Init() tea.Cmd {
|
func (a *Autocomplete) Init() tea.Cmd {
|
||||||
return textinput.Blink
|
return textinput.Blink
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/charmbracelet/bubbles/key"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MainPage struct {
|
type MainPage struct {
|
||||||
@ -14,9 +13,6 @@ type MainPage struct {
|
|||||||
|
|
||||||
taskPage common.Component
|
taskPage common.Component
|
||||||
timePage common.Component
|
timePage common.Component
|
||||||
currentTab int
|
|
||||||
width int
|
|
||||||
height int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMainPage(common *common.Common) *MainPage {
|
func NewMainPage(common *common.Common) *MainPage {
|
||||||
@ -28,7 +24,6 @@ func NewMainPage(common *common.Common) *MainPage {
|
|||||||
m.timePage = NewTimePage(common)
|
m.timePage = NewTimePage(common)
|
||||||
|
|
||||||
m.activePage = m.taskPage
|
m.activePage = m.taskPage
|
||||||
m.currentTab = 0
|
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
@ -42,39 +37,17 @@ func (m *MainPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
m.width = msg.Width
|
|
||||||
m.height = msg.Height
|
|
||||||
m.common.SetSize(msg.Width, msg.Height)
|
m.common.SetSize(msg.Width, msg.Height)
|
||||||
|
|
||||||
tabHeight := lipgloss.Height(m.renderTabBar())
|
|
||||||
contentHeight := msg.Height - tabHeight
|
|
||||||
if contentHeight < 0 {
|
|
||||||
contentHeight = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
newMsg := tea.WindowSizeMsg{Width: msg.Width, Height: contentHeight}
|
|
||||||
activePage, cmd := m.activePage.Update(newMsg)
|
|
||||||
m.activePage = activePage.(common.Component)
|
|
||||||
return m, cmd
|
|
||||||
|
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
// Only handle tab key for page switching when at the top level (no subpages active)
|
// Only handle tab key for page switching when at the top level (no subpages active)
|
||||||
if key.Matches(msg, m.common.Keymap.Next) && !m.common.HasSubpages() {
|
if key.Matches(msg, m.common.Keymap.Next) && !m.common.HasSubpages() {
|
||||||
if m.activePage == m.taskPage {
|
if m.activePage == m.taskPage {
|
||||||
m.activePage = m.timePage
|
m.activePage = m.timePage
|
||||||
m.currentTab = 1
|
|
||||||
} else {
|
} else {
|
||||||
m.activePage = m.taskPage
|
m.activePage = m.taskPage
|
||||||
m.currentTab = 0
|
|
||||||
}
|
}
|
||||||
|
// Re-size the new active page just in case
|
||||||
tabHeight := lipgloss.Height(m.renderTabBar())
|
m.activePage.SetSize(m.common.Width(), m.common.Height())
|
||||||
contentHeight := m.height - tabHeight
|
|
||||||
if contentHeight < 0 {
|
|
||||||
contentHeight = 0
|
|
||||||
}
|
|
||||||
m.activePage.SetSize(m.width, contentHeight)
|
|
||||||
|
|
||||||
// Trigger a refresh/init on switch? Maybe not needed if we keep state.
|
// Trigger a refresh/init on switch? Maybe not needed if we keep state.
|
||||||
// But we might want to refresh data.
|
// But we might want to refresh data.
|
||||||
return m, m.activePage.Init()
|
return m, m.activePage.Init()
|
||||||
@ -87,22 +60,6 @@ func (m *MainPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, cmd
|
return m, cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MainPage) renderTabBar() string {
|
|
||||||
var tabs []string
|
|
||||||
headers := []string{"Tasks", "Time"}
|
|
||||||
|
|
||||||
for i, header := range headers {
|
|
||||||
style := m.common.Styles.Tab
|
|
||||||
if m.currentTab == i {
|
|
||||||
style = m.common.Styles.ActiveTab
|
|
||||||
}
|
|
||||||
tabs = append(tabs, style.Render(header))
|
|
||||||
}
|
|
||||||
|
|
||||||
row := lipgloss.JoinHorizontal(lipgloss.Top, tabs...)
|
|
||||||
return m.common.Styles.TabBar.Width(m.common.Width()).Render(row)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MainPage) View() string {
|
func (m *MainPage) View() string {
|
||||||
return lipgloss.JoinVertical(lipgloss.Left, m.renderTabBar(), m.activePage.View())
|
return m.activePage.View()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,8 +41,6 @@ type TaskEditorPage struct {
|
|||||||
area int
|
area int
|
||||||
areaPicker *areaPicker
|
areaPicker *areaPicker
|
||||||
areas []area
|
areas []area
|
||||||
|
|
||||||
infoViewport viewport.Model
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTaskEditorPage(com *common.Common, task taskwarrior.Task) *TaskEditorPage {
|
func NewTaskEditorPage(com *common.Common, task taskwarrior.Task) *TaskEditorPage {
|
||||||
@ -70,11 +68,6 @@ func NewTaskEditorPage(com *common.Common, task taskwarrior.Task) *TaskEditorPag
|
|||||||
|
|
||||||
p.areaPicker = NewAreaPicker(com, []string{"Task", "Tags", "Dates"})
|
p.areaPicker = NewAreaPicker(com, []string{"Task", "Tags", "Dates"})
|
||||||
|
|
||||||
p.infoViewport = viewport.New(0, 0)
|
|
||||||
if p.task.Uuid != "" {
|
|
||||||
p.infoViewport.SetContent(p.common.TW.GetInformation(&p.task))
|
|
||||||
}
|
|
||||||
|
|
||||||
p.columnCursor = 1
|
p.columnCursor = 1
|
||||||
if p.task.Uuid == "" {
|
if p.task.Uuid == "" {
|
||||||
p.mode = modeInsert
|
p.mode = modeInsert
|
||||||
@ -101,12 +94,6 @@ func (p *TaskEditorPage) SetSize(width, height int) {
|
|||||||
} else {
|
} else {
|
||||||
p.colHeight = height - p.common.Styles.ColumnFocused.GetVerticalFrameSize()
|
p.colHeight = height - p.common.Styles.ColumnFocused.GetVerticalFrameSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
p.infoViewport.Width = width - p.colWidth - p.common.Styles.ColumnFocused.GetHorizontalFrameSize()*2 - 5
|
|
||||||
if p.infoViewport.Width < 0 {
|
|
||||||
p.infoViewport.Width = 0
|
|
||||||
}
|
|
||||||
p.infoViewport.Height = p.colHeight
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *TaskEditorPage) Init() tea.Cmd {
|
func (p *TaskEditorPage) Init() tea.Cmd {
|
||||||
@ -123,20 +110,12 @@ func (p *TaskEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
p.mode = mode(msg)
|
p.mode = mode(msg)
|
||||||
case prevColumnMsg:
|
case prevColumnMsg:
|
||||||
p.columnCursor--
|
p.columnCursor--
|
||||||
maxCols := 2
|
|
||||||
if p.task.Uuid != "" {
|
|
||||||
maxCols = 3
|
|
||||||
}
|
|
||||||
if p.columnCursor < 0 {
|
if p.columnCursor < 0 {
|
||||||
p.columnCursor = maxCols - 1
|
p.columnCursor = len(p.areas) - 1
|
||||||
}
|
}
|
||||||
case nextColumnMsg:
|
case nextColumnMsg:
|
||||||
p.columnCursor++
|
p.columnCursor++
|
||||||
maxCols := 2
|
if p.columnCursor > len(p.areas)-1 {
|
||||||
if p.task.Uuid != "" {
|
|
||||||
maxCols = 3
|
|
||||||
}
|
|
||||||
if p.columnCursor >= maxCols {
|
|
||||||
p.columnCursor = 0
|
p.columnCursor = 0
|
||||||
}
|
}
|
||||||
case prevAreaMsg:
|
case prevAreaMsg:
|
||||||
@ -187,26 +166,20 @@ func (p *TaskEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
picker, cmd := p.areaPicker.Update(msg)
|
picker, cmd := p.areaPicker.Update(msg)
|
||||||
p.areaPicker = picker.(*areaPicker)
|
p.areaPicker = picker.(*areaPicker)
|
||||||
return p, cmd
|
return p, cmd
|
||||||
} else if p.columnCursor == 1 {
|
} else {
|
||||||
model, cmd := p.areas[p.area].Update(prevFieldMsg{})
|
model, cmd := p.areas[p.area].Update(prevFieldMsg{})
|
||||||
p.areas[p.area] = model.(area)
|
p.areas[p.area] = model.(area)
|
||||||
return p, cmd
|
return p, cmd
|
||||||
} else if p.columnCursor == 2 {
|
|
||||||
p.infoViewport.LineUp(1)
|
|
||||||
return p, nil
|
|
||||||
}
|
}
|
||||||
case key.Matches(msg, p.common.Keymap.Down):
|
case key.Matches(msg, p.common.Keymap.Down):
|
||||||
if p.columnCursor == 0 {
|
if p.columnCursor == 0 {
|
||||||
picker, cmd := p.areaPicker.Update(msg)
|
picker, cmd := p.areaPicker.Update(msg)
|
||||||
p.areaPicker = picker.(*areaPicker)
|
p.areaPicker = picker.(*areaPicker)
|
||||||
return p, cmd
|
return p, cmd
|
||||||
} else if p.columnCursor == 1 {
|
} else {
|
||||||
model, cmd := p.areas[p.area].Update(nextFieldMsg{})
|
model, cmd := p.areas[p.area].Update(nextFieldMsg{})
|
||||||
p.areas[p.area] = model.(area)
|
p.areas[p.area] = model.(area)
|
||||||
return p, cmd
|
return p, cmd
|
||||||
} else if p.columnCursor == 2 {
|
|
||||||
p.infoViewport.LineDown(1)
|
|
||||||
return p, nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,23 +212,21 @@ func (p *TaskEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
picker, cmd := p.areaPicker.Update(msg)
|
picker, cmd := p.areaPicker.Update(msg)
|
||||||
p.areaPicker = picker.(*areaPicker)
|
p.areaPicker = picker.(*areaPicker)
|
||||||
return p, cmd
|
return p, cmd
|
||||||
} else if p.columnCursor == 1 {
|
} else {
|
||||||
model, cmd := p.areas[p.area].Update(prevFieldMsg{})
|
model, cmd := p.areas[p.area].Update(prevFieldMsg{})
|
||||||
p.areas[p.area] = model.(area)
|
p.areas[p.area] = model.(area)
|
||||||
return p, cmd
|
return p, cmd
|
||||||
}
|
}
|
||||||
return p, nil
|
|
||||||
case key.Matches(msg, p.common.Keymap.Next):
|
case key.Matches(msg, p.common.Keymap.Next):
|
||||||
if p.columnCursor == 0 {
|
if p.columnCursor == 0 {
|
||||||
picker, cmd := p.areaPicker.Update(msg)
|
picker, cmd := p.areaPicker.Update(msg)
|
||||||
p.areaPicker = picker.(*areaPicker)
|
p.areaPicker = picker.(*areaPicker)
|
||||||
return p, cmd
|
return p, cmd
|
||||||
} else if p.columnCursor == 1 {
|
} else {
|
||||||
model, cmd := p.areas[p.area].Update(nextFieldMsg{})
|
model, cmd := p.areas[p.area].Update(nextFieldMsg{})
|
||||||
p.areas[p.area] = model.(area)
|
p.areas[p.area] = model.(area)
|
||||||
return p, cmd
|
return p, cmd
|
||||||
}
|
}
|
||||||
return p, nil
|
|
||||||
case key.Matches(msg, p.common.Keymap.Ok):
|
case key.Matches(msg, p.common.Keymap.Ok):
|
||||||
model, cmd := p.areas[p.area].Update(msg)
|
model, cmd := p.areas[p.area].Update(msg)
|
||||||
if p.area != 3 {
|
if p.area != 3 {
|
||||||
@ -270,10 +241,6 @@ func (p *TaskEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
picker, cmd := p.areaPicker.Update(msg)
|
picker, cmd := p.areaPicker.Update(msg)
|
||||||
p.areaPicker = picker.(*areaPicker)
|
p.areaPicker = picker.(*areaPicker)
|
||||||
return p, cmd
|
return p, cmd
|
||||||
} else if p.columnCursor == 2 {
|
|
||||||
var cmd tea.Cmd
|
|
||||||
p.infoViewport, cmd = p.infoViewport.Update(msg)
|
|
||||||
return p, cmd
|
|
||||||
} else {
|
} else {
|
||||||
model, cmd := p.areas[p.area].Update(msg)
|
model, cmd := p.areas[p.area].Update(msg)
|
||||||
p.areas[p.area] = model.(area)
|
p.areas[p.area] = model.(area)
|
||||||
@ -286,31 +253,29 @@ func (p *TaskEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
func (p *TaskEditorPage) View() string {
|
func (p *TaskEditorPage) View() string {
|
||||||
var focusedStyle, blurredStyle lipgloss.Style
|
var focusedStyle, blurredStyle lipgloss.Style
|
||||||
if p.mode == modeInsert {
|
if p.mode == modeInsert {
|
||||||
focusedStyle = p.common.Styles.ColumnInsert
|
focusedStyle = p.common.Styles.ColumnInsert.Width(p.colWidth).Height(p.colHeight)
|
||||||
} else {
|
} else {
|
||||||
focusedStyle = p.common.Styles.ColumnFocused
|
focusedStyle = p.common.Styles.ColumnFocused.Width(p.colWidth).Height(p.colHeight)
|
||||||
}
|
}
|
||||||
blurredStyle = p.common.Styles.ColumnBlurred
|
blurredStyle = p.common.Styles.ColumnBlurred.Width(p.colWidth).Height(p.colHeight)
|
||||||
|
// var picker, area string
|
||||||
var area string
|
var area string
|
||||||
if p.columnCursor == 1 {
|
if p.columnCursor == 0 {
|
||||||
area = focusedStyle.Copy().Width(p.colWidth).Height(p.colHeight).Render(p.areas[p.area].View())
|
// picker = focusedStyle.Render(p.areaPicker.View())
|
||||||
|
area = blurredStyle.Render(p.areas[p.area].View())
|
||||||
} else {
|
} else {
|
||||||
area = blurredStyle.Copy().Width(p.colWidth).Height(p.colHeight).Render(p.areas[p.area].View())
|
// picker = blurredStyle.Render(p.areaPicker.View())
|
||||||
|
area = focusedStyle.Render(p.areas[p.area].View())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.task.Uuid != "" {
|
if p.task.Uuid != "" {
|
||||||
var infoView string
|
|
||||||
if p.columnCursor == 2 {
|
|
||||||
infoView = focusedStyle.Copy().Width(p.infoViewport.Width).Height(p.infoViewport.Height).Render(p.infoViewport.View())
|
|
||||||
} else {
|
|
||||||
infoView = blurredStyle.Copy().Width(p.infoViewport.Width).Height(p.infoViewport.Height).Render(p.infoViewport.View())
|
|
||||||
}
|
|
||||||
area = lipgloss.JoinHorizontal(
|
area = lipgloss.JoinHorizontal(
|
||||||
lipgloss.Top,
|
lipgloss.Top,
|
||||||
area,
|
area,
|
||||||
infoView,
|
p.common.Styles.ColumnFocused.Render(p.common.TW.GetInformation(&p.task)),
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tabs := ""
|
tabs := ""
|
||||||
|
|||||||
@ -5,10 +5,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"tasksquire/common"
|
"tasksquire/common"
|
||||||
"tasksquire/components/autocomplete"
|
"tasksquire/components/autocomplete"
|
||||||
|
"tasksquire/components/picker"
|
||||||
"tasksquire/components/timestampeditor"
|
"tasksquire/components/timestampeditor"
|
||||||
"tasksquire/timewarrior"
|
"tasksquire/timewarrior"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/charmbracelet/bubbles/key"
|
||||||
|
"github.com/charmbracelet/bubbles/list"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
@ -18,17 +20,65 @@ type TimeEditorPage struct {
|
|||||||
interval *timewarrior.Interval
|
interval *timewarrior.Interval
|
||||||
|
|
||||||
// Fields
|
// Fields
|
||||||
startEditor *timestampeditor.TimestampEditor
|
projectPicker *picker.Picker
|
||||||
endEditor *timestampeditor.TimestampEditor
|
startEditor *timestampeditor.TimestampEditor
|
||||||
tagsInput *autocomplete.Autocomplete
|
endEditor *timestampeditor.TimestampEditor
|
||||||
adjust bool
|
tagsInput *autocomplete.Autocomplete
|
||||||
|
adjust bool
|
||||||
|
|
||||||
// State
|
// State
|
||||||
currentField int
|
selectedProject string
|
||||||
totalFields int
|
currentField int
|
||||||
|
totalFields int
|
||||||
|
}
|
||||||
|
|
||||||
|
type timeEditorProjectSelectedMsg struct {
|
||||||
|
project string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTimeEditorPage(com *common.Common, interval *timewarrior.Interval) *TimeEditorPage {
|
func NewTimeEditorPage(com *common.Common, interval *timewarrior.Interval) *TimeEditorPage {
|
||||||
|
// Extract project from tags if it exists
|
||||||
|
projects := com.TW.GetProjects()
|
||||||
|
selectedProject, remainingTags := extractProjectFromTags(interval.Tags, projects)
|
||||||
|
if selectedProject == "" && len(projects) > 0 {
|
||||||
|
selectedProject = projects[0] // Default to first project (required)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create project picker with onCreate support for new projects
|
||||||
|
projectItemProvider := func() []list.Item {
|
||||||
|
projects := com.TW.GetProjects()
|
||||||
|
items := make([]list.Item, len(projects))
|
||||||
|
for i, proj := range projects {
|
||||||
|
items[i] = picker.NewItem(proj)
|
||||||
|
}
|
||||||
|
return items
|
||||||
|
}
|
||||||
|
|
||||||
|
projectOnSelect := func(item list.Item) tea.Cmd {
|
||||||
|
return func() tea.Msg {
|
||||||
|
return timeEditorProjectSelectedMsg{project: item.FilterValue()}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
projectOnCreate := func(name string) tea.Cmd {
|
||||||
|
return func() tea.Msg {
|
||||||
|
return timeEditorProjectSelectedMsg{project: name}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
projectPicker := picker.New(
|
||||||
|
com,
|
||||||
|
"Project",
|
||||||
|
projectItemProvider,
|
||||||
|
projectOnSelect,
|
||||||
|
picker.WithOnCreate(projectOnCreate),
|
||||||
|
picker.WithFilterByDefault(true),
|
||||||
|
)
|
||||||
|
projectPicker.SetSize(50, 10) // Compact size for inline use
|
||||||
|
if selectedProject != "" {
|
||||||
|
projectPicker.SelectItemByFilterValue(selectedProject)
|
||||||
|
}
|
||||||
|
|
||||||
// Create start timestamp editor
|
// Create start timestamp editor
|
||||||
startEditor := timestampeditor.New(com).
|
startEditor := timestampeditor.New(com).
|
||||||
Title("Start").
|
Title("Start").
|
||||||
@ -39,38 +89,50 @@ func NewTimeEditorPage(com *common.Common, interval *timewarrior.Interval) *Time
|
|||||||
Title("End").
|
Title("End").
|
||||||
ValueFromString(interval.End)
|
ValueFromString(interval.End)
|
||||||
|
|
||||||
// Create tags autocomplete with combinations from past intervals
|
// Get tag combinations filtered by selected project
|
||||||
tagCombinations := com.TimeW.GetTagCombinations()
|
tagCombinations := filterTagCombinationsByProject(
|
||||||
|
com.TimeW.GetTagCombinations(),
|
||||||
|
selectedProject,
|
||||||
|
)
|
||||||
|
|
||||||
tagsInput := autocomplete.New(tagCombinations, 3, 10)
|
tagsInput := autocomplete.New(tagCombinations, 3, 10)
|
||||||
tagsInput.SetPlaceholder("Space separated, use \"\" for tags with spaces")
|
tagsInput.SetPlaceholder("Space separated, use \"\" for tags with spaces")
|
||||||
tagsInput.SetValue(formatTags(interval.Tags))
|
tagsInput.SetValue(formatTags(remainingTags)) // Use remaining tags (without project)
|
||||||
tagsInput.SetWidth(50)
|
tagsInput.SetWidth(50)
|
||||||
|
|
||||||
p := &TimeEditorPage{
|
p := &TimeEditorPage{
|
||||||
common: com,
|
common: com,
|
||||||
interval: interval,
|
interval: interval,
|
||||||
startEditor: startEditor,
|
projectPicker: projectPicker,
|
||||||
endEditor: endEditor,
|
startEditor: startEditor,
|
||||||
tagsInput: tagsInput,
|
endEditor: endEditor,
|
||||||
adjust: true, // Enable :adjust by default
|
tagsInput: tagsInput,
|
||||||
currentField: 0,
|
adjust: true, // Enable :adjust by default
|
||||||
totalFields: 4, // Updated to include adjust field
|
selectedProject: selectedProject,
|
||||||
|
currentField: 0,
|
||||||
|
totalFields: 5, // Now 5 fields: project, tags, start, end, adjust
|
||||||
}
|
}
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *TimeEditorPage) Init() tea.Cmd {
|
func (p *TimeEditorPage) Init() tea.Cmd {
|
||||||
// Focus the first field (tags)
|
// Focus the first field (project picker)
|
||||||
p.currentField = 0
|
p.currentField = 0
|
||||||
p.tagsInput.Focus()
|
return p.projectPicker.Init()
|
||||||
return p.tagsInput.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *TimeEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (p *TimeEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
var cmds []tea.Cmd
|
var cmds []tea.Cmd
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
|
case timeEditorProjectSelectedMsg:
|
||||||
|
// Update selected project
|
||||||
|
p.selectedProject = msg.project
|
||||||
|
// Refresh tag autocomplete with filtered combinations
|
||||||
|
cmds = append(cmds, p.updateTagSuggestions())
|
||||||
|
return p, tea.Batch(cmds...)
|
||||||
|
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch {
|
switch {
|
||||||
case key.Matches(msg, p.common.Keymap.Back):
|
case key.Matches(msg, p.common.Keymap.Back):
|
||||||
@ -82,14 +144,18 @@ func (p *TimeEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return model, BackCmd
|
return model, BackCmd
|
||||||
|
|
||||||
case key.Matches(msg, p.common.Keymap.Ok):
|
case key.Matches(msg, p.common.Keymap.Ok):
|
||||||
// Save and exit
|
// Don't save if the project picker is focused - let it handle Enter
|
||||||
p.saveInterval()
|
if p.currentField != 0 {
|
||||||
model, err := p.common.PopPage()
|
// Save and exit
|
||||||
if err != nil {
|
p.saveInterval()
|
||||||
slog.Error("page stack empty")
|
model, err := p.common.PopPage()
|
||||||
return nil, tea.Quit
|
if err != nil {
|
||||||
|
slog.Error("page stack empty")
|
||||||
|
return nil, tea.Quit
|
||||||
|
}
|
||||||
|
return model, tea.Batch(tea.Batch(cmds...), refreshIntervals)
|
||||||
}
|
}
|
||||||
return model, tea.Batch(tea.Batch(cmds...), refreshIntervals)
|
// If picker is focused, let it handle the key below
|
||||||
|
|
||||||
case key.Matches(msg, p.common.Keymap.Next):
|
case key.Matches(msg, p.common.Keymap.Next):
|
||||||
// Move to next field
|
// Move to next field
|
||||||
@ -111,25 +177,31 @@ func (p *TimeEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
// Update the currently focused field
|
// Update the currently focused field
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
switch p.currentField {
|
switch p.currentField {
|
||||||
case 0:
|
case 0: // Project picker
|
||||||
|
var model tea.Model
|
||||||
|
model, cmd = p.projectPicker.Update(msg)
|
||||||
|
if pk, ok := model.(*picker.Picker); ok {
|
||||||
|
p.projectPicker = pk
|
||||||
|
}
|
||||||
|
case 1: // Tags (was 0)
|
||||||
var model tea.Model
|
var model tea.Model
|
||||||
model, cmd = p.tagsInput.Update(msg)
|
model, cmd = p.tagsInput.Update(msg)
|
||||||
if ac, ok := model.(*autocomplete.Autocomplete); ok {
|
if ac, ok := model.(*autocomplete.Autocomplete); ok {
|
||||||
p.tagsInput = ac
|
p.tagsInput = ac
|
||||||
}
|
}
|
||||||
case 1:
|
case 2: // Start (was 1)
|
||||||
var model tea.Model
|
var model tea.Model
|
||||||
model, cmd = p.startEditor.Update(msg)
|
model, cmd = p.startEditor.Update(msg)
|
||||||
if editor, ok := model.(*timestampeditor.TimestampEditor); ok {
|
if editor, ok := model.(*timestampeditor.TimestampEditor); ok {
|
||||||
p.startEditor = editor
|
p.startEditor = editor
|
||||||
}
|
}
|
||||||
case 2:
|
case 3: // End (was 2)
|
||||||
var model tea.Model
|
var model tea.Model
|
||||||
model, cmd = p.endEditor.Update(msg)
|
model, cmd = p.endEditor.Update(msg)
|
||||||
if editor, ok := model.(*timestampeditor.TimestampEditor); ok {
|
if editor, ok := model.(*timestampeditor.TimestampEditor); ok {
|
||||||
p.endEditor = editor
|
p.endEditor = editor
|
||||||
}
|
}
|
||||||
case 3:
|
case 4: // Adjust (was 3)
|
||||||
// Handle adjust toggle with space/enter
|
// Handle adjust toggle with space/enter
|
||||||
if msg, ok := msg.(tea.KeyMsg); ok {
|
if msg, ok := msg.(tea.KeyMsg); ok {
|
||||||
if msg.String() == " " || msg.String() == "enter" {
|
if msg.String() == " " || msg.String() == "enter" {
|
||||||
@ -145,13 +217,15 @@ func (p *TimeEditorPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
func (p *TimeEditorPage) focusCurrentField() tea.Cmd {
|
func (p *TimeEditorPage) focusCurrentField() tea.Cmd {
|
||||||
switch p.currentField {
|
switch p.currentField {
|
||||||
case 0:
|
case 0:
|
||||||
|
return p.projectPicker.Init() // Picker doesn't have explicit Focus()
|
||||||
|
case 1:
|
||||||
p.tagsInput.Focus()
|
p.tagsInput.Focus()
|
||||||
return p.tagsInput.Init()
|
return p.tagsInput.Init()
|
||||||
case 1:
|
|
||||||
return p.startEditor.Focus()
|
|
||||||
case 2:
|
case 2:
|
||||||
return p.endEditor.Focus()
|
return p.startEditor.Focus()
|
||||||
case 3:
|
case 3:
|
||||||
|
return p.endEditor.Focus()
|
||||||
|
case 4:
|
||||||
// Adjust checkbox doesn't need focus action
|
// Adjust checkbox doesn't need focus action
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -161,12 +235,14 @@ func (p *TimeEditorPage) focusCurrentField() tea.Cmd {
|
|||||||
func (p *TimeEditorPage) blurCurrentField() {
|
func (p *TimeEditorPage) blurCurrentField() {
|
||||||
switch p.currentField {
|
switch p.currentField {
|
||||||
case 0:
|
case 0:
|
||||||
p.tagsInput.Blur()
|
// Picker doesn't have explicit Blur(), state handled by Update
|
||||||
case 1:
|
case 1:
|
||||||
p.startEditor.Blur()
|
p.tagsInput.Blur()
|
||||||
case 2:
|
case 2:
|
||||||
p.endEditor.Blur()
|
p.startEditor.Blur()
|
||||||
case 3:
|
case 3:
|
||||||
|
p.endEditor.Blur()
|
||||||
|
case 4:
|
||||||
// Adjust checkbox doesn't need blur action
|
// Adjust checkbox doesn't need blur action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,10 +255,22 @@ func (p *TimeEditorPage) View() string {
|
|||||||
sections = append(sections, titleStyle.Render("Edit Time Interval"))
|
sections = append(sections, titleStyle.Render("Edit Time Interval"))
|
||||||
sections = append(sections, "")
|
sections = append(sections, "")
|
||||||
|
|
||||||
// Tags input (now first)
|
// Project picker (field 0)
|
||||||
|
if p.currentField == 0 {
|
||||||
|
sections = append(sections, p.projectPicker.View())
|
||||||
|
} else {
|
||||||
|
blurredLabelStyle := p.common.Styles.Form.Blurred.Title
|
||||||
|
sections = append(sections, blurredLabelStyle.Render("Project"))
|
||||||
|
sections = append(sections, lipgloss.NewStyle().Faint(true).Render(p.selectedProject))
|
||||||
|
}
|
||||||
|
|
||||||
|
sections = append(sections, "")
|
||||||
|
sections = append(sections, "")
|
||||||
|
|
||||||
|
// Tags input (now field 1, was first)
|
||||||
tagsLabelStyle := p.common.Styles.Form.Focused.Title
|
tagsLabelStyle := p.common.Styles.Form.Focused.Title
|
||||||
tagsLabel := tagsLabelStyle.Render("Tags")
|
tagsLabel := tagsLabelStyle.Render("Tags")
|
||||||
if p.currentField == 0 {
|
if p.currentField == 1 { // Changed from 0
|
||||||
sections = append(sections, tagsLabel)
|
sections = append(sections, tagsLabel)
|
||||||
sections = append(sections, p.tagsInput.View())
|
sections = append(sections, p.tagsInput.View())
|
||||||
descStyle := p.common.Styles.Form.Focused.Description
|
descStyle := p.common.Styles.Form.Focused.Description
|
||||||
@ -204,7 +292,7 @@ func (p *TimeEditorPage) View() string {
|
|||||||
sections = append(sections, p.endEditor.View())
|
sections = append(sections, p.endEditor.View())
|
||||||
sections = append(sections, "")
|
sections = append(sections, "")
|
||||||
|
|
||||||
// Adjust checkbox
|
// Adjust checkbox (now field 4, was 3)
|
||||||
adjustLabelStyle := p.common.Styles.Form.Focused.Title
|
adjustLabelStyle := p.common.Styles.Form.Focused.Title
|
||||||
adjustLabel := adjustLabelStyle.Render("Adjust overlaps")
|
adjustLabel := adjustLabelStyle.Render("Adjust overlaps")
|
||||||
|
|
||||||
@ -215,7 +303,7 @@ func (p *TimeEditorPage) View() string {
|
|||||||
checkbox = "[ ]"
|
checkbox = "[ ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.currentField == 3 {
|
if p.currentField == 4 { // Changed from 3
|
||||||
focusedStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("12"))
|
focusedStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("12"))
|
||||||
sections = append(sections, adjustLabel)
|
sections = append(sections, adjustLabel)
|
||||||
sections = append(sections, focusedStyle.Render(checkbox+" Auto-adjust overlapping intervals"))
|
sections = append(sections, focusedStyle.Render(checkbox+" Auto-adjust overlapping intervals"))
|
||||||
@ -254,8 +342,24 @@ func (p *TimeEditorPage) saveInterval() {
|
|||||||
p.interval.Start = p.startEditor.GetValueString()
|
p.interval.Start = p.startEditor.GetValueString()
|
||||||
p.interval.End = p.endEditor.GetValueString()
|
p.interval.End = p.endEditor.GetValueString()
|
||||||
|
|
||||||
// Parse tags
|
// Parse tags from input
|
||||||
p.interval.Tags = parseTags(p.tagsInput.GetValue())
|
tags := parseTags(p.tagsInput.GetValue())
|
||||||
|
|
||||||
|
// Add project to tags if not already present
|
||||||
|
if p.selectedProject != "" {
|
||||||
|
projectExists := false
|
||||||
|
for _, tag := range tags {
|
||||||
|
if tag == p.selectedProject {
|
||||||
|
projectExists = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !projectExists {
|
||||||
|
tags = append([]string{p.selectedProject}, tags...) // Prepend project
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p.interval.Tags = tags
|
||||||
|
|
||||||
err := p.common.TimeW.ModifyInterval(p.interval, p.adjust)
|
err := p.common.TimeW.ModifyInterval(p.interval, p.adjust)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -298,3 +402,79 @@ func formatTags(tags []string) string {
|
|||||||
}
|
}
|
||||||
return strings.Join(formatted, " ")
|
return strings.Join(formatted, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// extractProjectFromTags finds and removes the first tag that matches a known project
|
||||||
|
// Returns the found project (or empty string) and the remaining tags
|
||||||
|
func extractProjectFromTags(tags []string, projects []string) (string, []string) {
|
||||||
|
projectSet := make(map[string]bool)
|
||||||
|
for _, p := range projects {
|
||||||
|
projectSet[p] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
var foundProject string
|
||||||
|
var remaining []string
|
||||||
|
|
||||||
|
for _, tag := range tags {
|
||||||
|
if foundProject == "" && projectSet[tag] {
|
||||||
|
foundProject = tag // First matching project
|
||||||
|
} else {
|
||||||
|
remaining = append(remaining, tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return foundProject, remaining
|
||||||
|
}
|
||||||
|
|
||||||
|
// filterTagCombinationsByProject filters tag combinations to only show those
|
||||||
|
// containing the exact project tag, and removes the project from the displayed combination
|
||||||
|
func filterTagCombinationsByProject(combinations []string, project string) []string {
|
||||||
|
if project == "" {
|
||||||
|
return combinations
|
||||||
|
}
|
||||||
|
|
||||||
|
var filtered []string
|
||||||
|
for _, combo := range combinations {
|
||||||
|
// Parse the combination into individual tags
|
||||||
|
tags := parseTags(combo)
|
||||||
|
|
||||||
|
// Check if project exists in this combination
|
||||||
|
for _, tag := range tags {
|
||||||
|
if tag == project {
|
||||||
|
// Found the project - now remove it from display
|
||||||
|
var displayTags []string
|
||||||
|
for _, t := range tags {
|
||||||
|
if t != project {
|
||||||
|
displayTags = append(displayTags, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(displayTags) > 0 {
|
||||||
|
filtered = append(filtered, formatTags(displayTags))
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filtered
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateTagSuggestions refreshes the tag autocomplete with filtered combinations
|
||||||
|
func (p *TimeEditorPage) updateTagSuggestions() tea.Cmd {
|
||||||
|
combinations := filterTagCombinationsByProject(
|
||||||
|
p.common.TimeW.GetTagCombinations(),
|
||||||
|
p.selectedProject,
|
||||||
|
)
|
||||||
|
|
||||||
|
// Update autocomplete suggestions
|
||||||
|
currentValue := p.tagsInput.GetValue()
|
||||||
|
p.tagsInput.SetSuggestions(combinations)
|
||||||
|
p.tagsInput.SetValue(currentValue)
|
||||||
|
|
||||||
|
// If tags field is focused, refocus it
|
||||||
|
if p.currentField == 1 {
|
||||||
|
p.tagsInput.Focus()
|
||||||
|
return p.tagsInput.Init()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user