From 3c054fccca06f6a3f11aa1b4837c78dfaf2651ea Mon Sep 17 00:00:00 2001 From: Dhruv Thakur Date: Mon, 10 Jun 2024 18:32:22 +0200 Subject: [PATCH] feat: show unsynced count --- internal/ui/model.go | 2 ++ internal/ui/styles.go | 10 ++++++++-- internal/ui/update.go | 6 ++++++ internal/ui/view.go | 13 +++++++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/internal/ui/model.go b/internal/ui/model.go index 96fe8a9..8243841 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -66,6 +66,7 @@ type model struct { issueIndexMap map[string]int issuesFetched bool worklogList list.Model + unsyncedWLCount uint syncedWorklogList list.Model activeIssueBeginTS time.Time activeIssueEndTS time.Time @@ -89,6 +90,7 @@ func (m model) Init() tea.Cmd { return tea.Batch( hideHelp(time.Minute*1), fetchJIRAIssues(m.jiraClient, m.jql), + fetchLogEntries(m.db), fetchSyncedLogEntries(m.db), ) } diff --git a/internal/ui/styles.go b/internal/ui/styles.go index 034a2ec..c50a8bf 100644 --- a/internal/ui/styles.go +++ b/internal/ui/styles.go @@ -11,7 +11,8 @@ const ( issueListColor = "#fe8019" worklogListColor = "#fabd2f" syncedWorklogListColor = "#b8bb26" - trackingColor = "#fabd2f" + trackingColor = "#fe8019" + unsyncedCountColor = "#fabd2f" activeIssueKeyColor = "#d3869b" activeIssueSummaryColor = "#8ec07c" issueStatusColor = "#665c54" @@ -22,7 +23,7 @@ const ( formFieldNameColor = "#8ec07c" formContextColor = "#fabd2f" aggTimeSpentColor = "#928374" - helpMsgColor = "#83a598" + helpMsgColor = "#7c6f64" helpViewTitleColor = "#83a598" helpHeaderColor = "#83a598" helpSectionColor = "#fabd2f" @@ -148,6 +149,11 @@ var ( PaddingLeft(2). Foreground(lipgloss.Color(aggTimeSpentColor)) + unsyncedCountStyle = lipgloss.NewStyle(). + PaddingLeft(2). + Bold(true). + Foreground(lipgloss.Color(unsyncedCountColor)) + helpTitleStyle = baseStyle.Copy(). Bold(true). Background(lipgloss.Color(helpViewTitleColor)). diff --git a/internal/ui/update.go b/internal/ui/update.go index a320f85..39c0ce9 100644 --- a/internal/ui/update.go +++ b/internal/ui/update.go @@ -432,6 +432,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { for i := range m.trackingInputs { m.trackingInputs[i].SetValue("") } + m.unsyncedWLCount++ } case ManualEntryUpdated: if msg.err != nil { @@ -456,6 +457,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { items = append(items, list.Item(e)) } m.worklogList.SetItems(items) + m.unsyncedWLCount = uint(len(msg.entries)) } case SyncedLogEntriesFetchedMsg: if msg.err != nil { @@ -474,6 +476,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { msg.entry.Error = msg.err m.messages = append(m.messages, msg.err.Error()) m.worklogList.SetItem(msg.index, msg.entry) + } else { + m.unsyncedWLCount-- } case FetchActiveMsg: if msg.err != nil { @@ -507,6 +511,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.messages = append(m.messages, message) } else { cmds = append(cmds, fetchLogEntries(m.db)) + m.unsyncedWLCount-- } case WLAddedOnJIRA: if msg.err != nil { @@ -540,6 +545,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { activeIssue.trackingActive = false } m.trackingActive = false + m.unsyncedWLCount++ } else { m.lastChange = InsertChange if activeIssue != nil { diff --git a/internal/ui/view.go b/internal/ui/view.go index 128ebc9..dbc6973 100644 --- a/internal/ui/view.go +++ b/internal/ui/view.go @@ -129,10 +129,19 @@ func (m model) View() string { helpMsg = " " + helpMsgStyle.Render("Press ? for help") } - footerStr := fmt.Sprintf("%s%s%s", + var unsyncedMsg string + if m.unsyncedWLCount > 0 { + entryWord := "entries" + if m.unsyncedWLCount == 1 { + entryWord = "entry" + } + unsyncedMsg = unsyncedCountStyle.Render(fmt.Sprintf("(%d unsynced %s)", m.unsyncedWLCount, entryWord)) + } + footerStr := fmt.Sprintf("%s%s%s%s", modeStyle.Render("punchout"), - helpMsg, + unsyncedMsg, activeMsg, + helpMsg, ) footer = footerStyle.Render(footerStr)