diff options
Diffstat (limited to 'internal/tui/app.go')
-rw-r--r-- | internal/tui/app.go | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/internal/tui/app.go b/internal/tui/app.go index 28f04dc..e325116 100644 --- a/internal/tui/app.go +++ b/internal/tui/app.go @@ -2,6 +2,7 @@ package tui import ( "context" + "fmt" "time" "punchcard/internal/queries" @@ -121,7 +122,7 @@ func (m AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.height = msg.Height case tea.KeyMsg: - cmds = append(cmds, HandleKeyPress(msg, m)) + cmds = append(cmds, HandleKeyPress(msg, &m)) case TickMsg: m.timerBox.currentTime = time.Time(msg) @@ -165,11 +166,67 @@ func (m AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case searchActivated: m.modalBox.activate(ModalTypeSearch) + case modalClosed: + m.modalBox.deactivate() + + case openTimeEntryEditor: + if m.selectedBox == HistoryBox && m.historyBox.viewLevel == HistoryLevelDetails { + m.openEntryEditor() + } + + case openModalUnchanged: + m.modalBox.Active = true + + case openDeleteConfirmation: + if m.selectedBox == HistoryBox && m.historyBox.viewLevel == HistoryLevelDetails { + m.modalBox.activate(ModalTypeDeleteConfirmation) + m.modalBox.editedID = m.historyBox.selectedEntry().ID + } + + case recheckBounds: + switch m.selectedBox { + case HistoryBox: + m.historyBox.recheckBounds() + } + } return m, tea.Batch(cmds...) } +func (m *AppModel) openEntryEditor() { + m.modalBox.activate(ModalTypeEntry) + m.modalBox.editedID = m.historyBox.selectedEntry().ID + f := m.modalBox.form + f.fields[0].Focus() + + entry := m.historyBox.selectedEntry() + f.fields[0].SetValue(entry.StartTime.Format(time.DateTime)) + if entry.EndTime.Valid { + f.fields[1].SetValue(entry.EndTime.Time.Format(time.DateTime)) + } + for _, client := range m.projectsBox.clients { + if client.ID == entry.ClientID { + f.fields[2].SetValue(client.Name) + break + } + } + if entry.ProjectID.Valid { + for _, project := range m.projectsBox.projects[entry.ClientID] { + if project.ID == entry.ProjectID.Int64 { + f.fields[3].SetValue(project.Name) + break + } + } + } + if entry.Description.Valid { + f.fields[4].SetValue(entry.Description.String) + } + if entry.BillableRate.Valid { + f.fields[5].SetValue(fmt.Sprintf("%.2f", float64(entry.BillableRate.Int64)/100)) + } +} + // View renders the app func (m AppModel) View() string { if m.width == 0 || m.height == 0 { @@ -209,10 +266,10 @@ func (m AppModel) View() string { leftColumn := lipgloss.JoinVertical(lipgloss.Left, timerBox, projectsBox) mainContent := lipgloss.JoinHorizontal(lipgloss.Top, leftColumn, historyBox) - keyBindings := activeBindings(m.selectedBox, m.historyBox.viewLevel) + keyBindings := activeBindings(m.selectedBox, m.historyBox.viewLevel, m.modalBox) bottomBar := RenderBottomBar(m, keyBindings, m.err) - return m.modalBox.RenderCenteredOver(topBar + "\n" + mainContent + "\n" + bottomBar, m) + return m.modalBox.RenderCenteredOver(topBar+"\n"+mainContent+"\n"+bottomBar, m) } // dataUpdatedMsg is sent when data is updated from the database |