Add time page
This commit is contained in:
@ -21,17 +21,25 @@ func NewProjectPickerPage(common *common.Common, activeProject string) *ProjectP
|
||||
common: common,
|
||||
}
|
||||
|
||||
projects := common.TW.GetProjects()
|
||||
items := []list.Item{picker.NewItem("(none)")}
|
||||
for _, proj := range projects {
|
||||
items = append(items, picker.NewItem(proj))
|
||||
itemProvider := func() []list.Item {
|
||||
projects := common.TW.GetProjects()
|
||||
items := []list.Item{picker.NewItem("(none)")}
|
||||
for _, proj := range projects {
|
||||
items = append(items, picker.NewItem(proj))
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
onSelect := func(item list.Item) tea.Cmd {
|
||||
return func() tea.Msg { return projectSelectedMsg{item: item} }
|
||||
}
|
||||
|
||||
p.picker = picker.New(common, "Projects", items, onSelect)
|
||||
// onCreate := func(name string) tea.Cmd {
|
||||
// return func() tea.Msg { return projectSelectedMsg{item: picker.NewItem(name)} }
|
||||
// }
|
||||
|
||||
// p.picker = picker.New(common, "Projects", itemProvider, onSelect, picker.WithOnCreate(onCreate))
|
||||
p.picker = picker.New(common, "Projects", itemProvider, onSelect)
|
||||
|
||||
// Set active project
|
||||
if activeProject == "" {
|
||||
@ -74,7 +82,7 @@ func (p *ProjectPickerPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
case tea.WindowSizeMsg:
|
||||
p.SetSize(msg.Width, msg.Height)
|
||||
case projectSelectedMsg:
|
||||
proj := msg.item.(picker.Item).Title()
|
||||
proj := msg.item.FilterValue() // Use FilterValue (text)
|
||||
if proj == "(none)" {
|
||||
proj = ""
|
||||
}
|
||||
@ -86,14 +94,16 @@ func (p *ProjectPickerPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
return model, func() tea.Msg { return UpdateProjectMsg(proj) }
|
||||
case tea.KeyMsg:
|
||||
switch {
|
||||
case key.Matches(msg, p.common.Keymap.Back):
|
||||
model, err := p.common.PopPage()
|
||||
if err != nil {
|
||||
slog.Error("page stack empty")
|
||||
return nil, tea.Quit
|
||||
if !p.picker.IsFiltering() {
|
||||
switch {
|
||||
case key.Matches(msg, p.common.Keymap.Back):
|
||||
model, err := p.common.PopPage()
|
||||
if err != nil {
|
||||
slog.Error("page stack empty")
|
||||
return nil, tea.Quit
|
||||
}
|
||||
return model, BackCmd
|
||||
}
|
||||
return model, BackCmd
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,4 +133,4 @@ func (p *ProjectPickerPage) updateProjectCmd() tea.Msg {
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateProjectMsg string
|
||||
type UpdateProjectMsg string
|
||||
Reference in New Issue
Block a user