Skip to content

Commit

Permalink
feat: show unsynced count
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Jun 10, 2024
1 parent 1698248 commit 3c054fc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions internal/ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
)
}
10 changes: 8 additions & 2 deletions internal/ui/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const (
issueListColor = "#fe8019"
worklogListColor = "#fabd2f"
syncedWorklogListColor = "#b8bb26"
trackingColor = "#fabd2f"
trackingColor = "#fe8019"
unsyncedCountColor = "#fabd2f"
activeIssueKeyColor = "#d3869b"
activeIssueSummaryColor = "#8ec07c"
issueStatusColor = "#665c54"
Expand All @@ -22,7 +23,7 @@ const (
formFieldNameColor = "#8ec07c"
formContextColor = "#fabd2f"
aggTimeSpentColor = "#928374"
helpMsgColor = "#83a598"
helpMsgColor = "#7c6f64"
helpViewTitleColor = "#83a598"
helpHeaderColor = "#83a598"
helpSectionColor = "#fabd2f"
Expand Down Expand Up @@ -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)).
Expand Down
6 changes: 6 additions & 0 deletions internal/ui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions internal/ui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 3c054fc

Please sign in to comment.