summaryrefslogtreecommitdiff
path: root/internal/tui/commands.go
blob: be5c8dcc5022237ceef0b1403e4f412b48940ebe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package tui

import (
	"context"

	"punchcard/internal/actions"

	tea "github.com/charmbracelet/bubbletea"
)

type (
	navigationMsg          struct{ Forward bool }
	selectionMsg           struct{ Forward bool }
	drillDownMsg           struct{}
	drillUpMsg             struct{}
	searchActivated        struct{}
	modalClosed            struct{}
	openTimeEntryEditor    struct{}
	openModalUnchanged     struct{}
	openDeleteConfirmation struct{}
	recheckBounds          struct{}
)

func navigate(forward bool) tea.Cmd {
	return func() tea.Msg { return navigationMsg{forward} }
}

func punchIn(m AppModel) tea.Cmd {
	return func() tea.Msg {
		_, _ = actions.New(m.queries).PunchInMostRecent(context.Background(), "", nil)
		// TODO: use the returned TimerSession instead of re-querying everything
		return m.refreshCmd()
	}
}

func punchOut(m AppModel) tea.Cmd {
	return func() tea.Msg {
		_, _ = actions.New(m.queries).PunchOut(context.Background())
		// TODO: use the returned TimerSession instead of re-querying everything
		return m.refreshCmd()
	}
}

func punchInOnSelection(m AppModel) tea.Cmd {
	return func() tea.Msg {
		var clientID, projectID, description string
		var entryRate *float64
		switch m.selectedBox {
		case ProjectsBox:
			clientID, projectID, description, entryRate = m.projectsBox.selection()
		case HistoryBox:
			clientID, projectID, description, entryRate = m.historyBox.selection()
		}

		_, _ = actions.New(m.queries).PunchIn(context.Background(), clientID, projectID, description, entryRate)
		// TODO: use the returned TimerSession instead of re-querying everything
		return m.refreshCmd()
	}
}

func selectHistorySummary() tea.Cmd {
	return func() tea.Msg { return drillDownMsg{} }
}

func backToHistorySummary() tea.Cmd {
	return func() tea.Msg { return drillUpMsg{} }
}

func changeSelection(forward bool) tea.Cmd {
	return func() tea.Msg { return selectionMsg{forward} }
}

func activateSearch() tea.Cmd {
	return func() tea.Msg { return searchActivated{} }
}

func closeModal() tea.Cmd {
	return func() tea.Msg { return modalClosed{} }
}

func editCurrentEntry() tea.Cmd {
	return func() tea.Msg { return openTimeEntryEditor{} }
}

func reOpenModal() tea.Cmd {
	return func() tea.Msg { return openModalUnchanged{} }
}

func confirmDeleteEntry() tea.Cmd {
	return func() tea.Msg { return openDeleteConfirmation{} }
}