Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions internal/api/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,32 @@ func FetchEntriesForWeek(apiKey, workspaceId, userId string, weekStart time.Time
}
}

// FetchEntriesForWeek returns a command that fetches time entries for a specific week
func FetchEntriesForMonth(apiKey, workspaceId, userId string, requestedDate time.Time) tea.Cmd {
return func() tea.Msg {
client := NewClient(apiKey)

monthStart := time.Date(requestedDate.Year(), requestedDate.Month(), 1, 0, 0, 0, 0, time.UTC)
monthEnd := time.Date(requestedDate.Year(), requestedDate.Month()+1, 1, 0, 0, 0, 0, time.UTC).Add(-time.Second)

startStr := monthStart.Format("2006-01-02")
endStr := monthEnd.Format("2006-01-02")

endpoint := "/workspaces/%s/user/%s/time-entries?start=%sT00:00:00Z&end=%sT23:59:59Z"
body, err := client.Get(fmt.Sprintf(endpoint, workspaceId, userId, startStr, endStr))
if err != nil {
return messages.ErrorMsg{Err: err}
}

var entries []models.Entry
if err := json.Unmarshal(body, &entries); err != nil {
return messages.ErrorMsg{Err: fmt.Errorf("failed to parse entries: %w", err)}
}

return messages.EntriesLoadedMsg{Entries: entries}
}
}

// CreateTimeEntry creates a new time entry in Clockify
// Takes all the necessary parameters and returns an error if creation fails
func (c *Client) CreateTimeEntry(workspaceID, projectID, taskID, description, startTimeStr, endTimeStr string, date time.Time) (models.Entry, error) {
Expand Down
23 changes: 21 additions & 2 deletions internal/ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"clockify-app/internal/ui/components/help"
"clockify-app/internal/ui/components/modal"
"clockify-app/internal/ui/views/entries"
"clockify-app/internal/ui/views/month"
"clockify-app/internal/ui/views/project"
"clockify-app/internal/ui/views/projects"
"clockify-app/internal/ui/views/settings"
Expand All @@ -30,6 +31,7 @@ const (
SettingsView View = iota
EntriesView
WeekView
MonthView
ProjectsView
ProjectView
)
Expand All @@ -42,6 +44,7 @@ type Page struct {
var pages = []Page{
{"Entries", EntriesView},
{"WeekView", WeekView},
{"MonthView", MonthView},
{"Projects", ProjectsView},
{"Settings", SettingsView},
}
Expand All @@ -62,6 +65,7 @@ type Model struct {
projectsView projects.Model // List of Projects
projectView project.Model // Single Project view
weekView week.Model // Week view
monthView month.Model // Month view

// Modal state
modal *modal.Model
Expand Down Expand Up @@ -93,6 +97,7 @@ func NewModel() Model {
entriesView: entries.New(cfg),
projectsView: projects.New(cfg),
weekView: week.New(cfg),
monthView: month.New(cfg),
ready: false,
}
}
Expand Down Expand Up @@ -127,6 +132,9 @@ func (m Model) initializeFirstViewCmd() tea.Cmd {
),
m.weekView.Init(),
)

case MonthView:
return m.monthView.Init()
}
return nil
}
Expand Down Expand Up @@ -165,6 +173,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.projectView, cmd = m.projectView.Update(msg)
case WeekView:
m.weekView.SetSize(m.width, m.height)
case MonthView:
m.monthView.SetSize(m.width, m.height)
case SettingsView:
m.settingsView.SetSize(m.width, m.height)
}
Expand All @@ -181,7 +191,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.String() {
case "ctrl+c", "q":
return m, tea.Quit
case "1", "2", "3", "4":
case "1", "2", "3", "4", "5":
if num, err := strconv.Atoi(msg.String()); err == nil {
m.currentView = pages[num-1].Key
m.viewport.SetContent(m.renderContent())
Expand All @@ -207,6 +217,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
),
m.weekView.Init(),
)
case MonthView:
m.monthView.SetSize(m.width, m.height)
return m, m.monthView.Init()
case SettingsView:
return m, settings.Init()
}
Expand Down Expand Up @@ -340,6 +353,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.entriesView, cmd = m.entriesView.Update(msg)
case WeekView:
m.weekView, cmd = m.weekView.Update(msg)
case MonthView:
m.monthView, cmd = m.monthView.Update(msg)
}
m.viewport.SetContent(m.renderContent())
return m, cmd
Expand Down Expand Up @@ -397,6 +412,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.projectView, cmd = m.projectView.Update(msg)
case WeekView:
m.weekView, cmd = m.weekView.Update(msg)
case MonthView:
m.monthView, cmd = m.monthView.Update(msg)
}
cmds = append(cmds, cmd)

Expand Down Expand Up @@ -426,7 +443,7 @@ func (m Model) View() string {
scrollbar := utils.RenderScrollbarSimple(m.viewport)

switch m.currentView {
case EntriesView, ProjectsView, WeekView:
case EntriesView, ProjectsView, WeekView, MonthView:
scrollbar = ""
}
// The viewport already contains the view content in Update
Expand Down Expand Up @@ -503,6 +520,8 @@ func (m Model) renderContent() string {
return m.projectView.View()
case WeekView:
return m.weekView.View()
case MonthView:
return m.monthView.View()
}

return ""
Expand Down
Loading
Loading