Skip to content

Commit

Permalink
ironing time control kinks
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Oct 22, 2024
1 parent 955920e commit e369822
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/slackdump/internal/ui/bubbles/btime/btime.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ func (m *Model) Blur() {
m.Focused = false
}

func (m *Model) SetTime(t time.Time) {
m.Time = t
m.toEntry()
}

func (m *Model) Init() tea.Cmd {
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/slackdump/internal/ui/cfgui/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cfgui
import (
"errors"
"os"
"time"

tea "github.com/charmbracelet/bubbletea"
"github.com/rusq/rbubbles/filemgr"
Expand Down Expand Up @@ -45,11 +46,13 @@ func effectiveConfig() configuration {
Name: "Start date",
Value: cfg.Oldest.String(),
Description: "The oldest message to fetch",
Model: updaters.NewDTTM((*time.Time)(&cfg.Oldest)),
},
{
Name: "End date",
Value: cfg.Latest.String(),
Description: "The newest message to fetch",
Model: updaters.NewDTTM((*time.Time)(&cfg.Latest)),
},
},
},
Expand Down
18 changes: 16 additions & 2 deletions cmd/slackdump/internal/ui/cfgui/updaters/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ func NewDTTM(ptrTime *time.Time) DateModel {
}

func (m DateModel) Init() tea.Cmd {
return m.dm.Init()
var cmds []tea.Cmd
if m.Value == nil || m.Value.IsZero() {
cmds = append(cmds, cmdSetValue("", time.Now()))
}
cmds = append(cmds, m.dm.Init(), m.tm.Init())
return tea.Batch(cmds...)
}

type state int
Expand All @@ -54,16 +59,25 @@ func (m DateModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmds []tea.Cmd

switch msg := msg.(type) {
case wmSetValue[time.Time]:
*m.Value = msg.v
m.dm.SetTime(msg.v)
m.tm.SetTime(msg.v)
case tea.KeyMsg:
switch msg.String() {
case "esc", "ctrl+c":
m.finishing = true
return m, OnClose
case "enter":
d := m.dm.Time
t := m.tm.Value()
*m.Value = time.Date(d.Year(), d.Month(), d.Day(), t.Hour(), t.Minute(), t.Second(), 0, m.Value.Location())
m.finishing = true
return m, OnClose
case "backspace":
*m.Value = time.Time{}
m.finishing = true
return m, OnClose
case "tab":
switch m.state {
case scalendar:
Expand Down Expand Up @@ -107,7 +121,7 @@ func (m DateModel) View() string {

var b strings.Builder

help := cfg.Theme.Help.Ellipsis.Render("arrow keys: adjust • tab/shift+tab: switch fields • enter: select")
help := cfg.Theme.Help.Ellipsis.Render("arrow keys: adjust • tab/shift+tab: switch fields\nenter: select • backspace: clear • esc: cancel")

var dateStyle lipgloss.Style
var timeStyle lipgloss.Style
Expand Down

0 comments on commit e369822

Please sign in to comment.