From bf06cc71301ec4351d0718a46713609083b50d57 Mon Sep 17 00:00:00 2001 From: Siddhanta <66236925+siddhantac@users.noreply.github.com> Date: Thu, 27 Jun 2024 22:36:22 +0800 Subject: [PATCH 1/3] add section for sorting-mode --- ui/model.go | 3 ++- ui/sort_mode.go | 34 ++++++++++++++++++++++++++++++++++ ui/style.go | 1 - 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 ui/sort_mode.go diff --git a/ui/model.go b/ui/model.go index 331cc82..195f857 100644 --- a/ui/model.go +++ b/ui/model.go @@ -215,7 +215,7 @@ func (m *model) View() string { mainView = activeTab.View() } - reportSectionTitleStyle := sectionTitleStyle.Copy() + reportSectionTitleStyle := sectionTitleStyle.Copy().MarginBottom(1) if !m.filterGroup.IsFocused() { reportSectionTitleStyle = reportSectionTitleStyle. Background(lipgloss.Color(colorscheme.Nord0)). @@ -233,6 +233,7 @@ func (m *model) View() string { m.tabs.View(), m.filterGroup.View(), m.period.View(), + sortingView(m.toggleSort), ), activeItemStyle.Render(mainView), ), diff --git a/ui/sort_mode.go b/ui/sort_mode.go new file mode 100644 index 0000000..d0e92cd --- /dev/null +++ b/ui/sort_mode.go @@ -0,0 +1,34 @@ +package ui + +import ( + "github.com/charmbracelet/lipgloss" +) + +func sortingView(isSortByAmount bool) string { + sortTitleStyle := sectionTitleStyle.Copy() + sectionTitle := sortTitleStyle. + MarginTop(1). + Render("SORT") + + inactiveTextStyle := lipgloss.NewStyle(). + Foreground(theme.PrimaryForeground). + MarginRight(2) + textStyle := lipgloss.NewStyle(). + MarginRight(2) + + var sortAmount, sortAccount string + if isSortByAmount { + sortAmount = textStyle.Render("amount") + sortAccount = inactiveTextStyle.Render("account") + } else { + sortAmount = inactiveTextStyle.Render("amount") + sortAccount = textStyle.Render("account") + } + + return lipgloss.JoinVertical( + lipgloss.Right, + sectionTitle, + sortAmount, + sortAccount, + ) +} diff --git a/ui/style.go b/ui/style.go index 8f3335b..c28ad93 100644 --- a/ui/style.go +++ b/ui/style.go @@ -38,7 +38,6 @@ var sectionTitleStyle = lipgloss.NewStyle(). MarginRight(1). PaddingRight(1). PaddingLeft(1). - MarginBottom(1). Foreground(theme.Accent) func getTableStyle() table.Styles { From 53d881c4cb3e572c0fe115f313aafc3cf2a5e2c5 Mon Sep 17 00:00:00 2001 From: Siddhanta <66236925+siddhantac@users.noreply.github.com> Date: Thu, 27 Jun 2024 22:45:27 +0800 Subject: [PATCH 2/3] refactored code for period active/inactive --- ui/period.go | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/ui/period.go b/ui/period.go index 2dec828..27b4202 100644 --- a/ui/period.go +++ b/ui/period.go @@ -37,31 +37,25 @@ func (p *Period) View() string { inactiveTextStyle := lipgloss.NewStyle(). Foreground(theme.PrimaryForeground). MarginRight(2) - textStyle := lipgloss.NewStyle(). + activeTextStyle := lipgloss.NewStyle(). MarginRight(2) - var weekView, monthView, quarterView, yearView string + var ( + weekView = inactiveTextStyle.Render("weekly") + monthView = inactiveTextStyle.Render("monthly") + quarterView = inactiveTextStyle.Render("quarterly") + yearView = inactiveTextStyle.Render("yearly") + ) + switch p.periodType { case hledger.PeriodWeekly: - weekView = textStyle.Render("weekly") - monthView = inactiveTextStyle.Render("monthly") - quarterView = inactiveTextStyle.Render("quarterly") - yearView = inactiveTextStyle.Render("yearly") + weekView = activeTextStyle.Render("weekly") case hledger.PeriodMonthly: - weekView = inactiveTextStyle.Render("weekly") - monthView = textStyle.Render("monthly") - quarterView = inactiveTextStyle.Render("quarterly") - yearView = inactiveTextStyle.Render("yearly") + monthView = activeTextStyle.Render("monthly") case hledger.PeriodQuarterly: - weekView = inactiveTextStyle.Render("weekly") - monthView = inactiveTextStyle.Render("monthly") - quarterView = textStyle.Render("quarterly") - yearView = inactiveTextStyle.Render("yearly") + quarterView = activeTextStyle.Render("quarterly") case hledger.PeriodYearly: - weekView = inactiveTextStyle.Render("weekly") - monthView = inactiveTextStyle.Render("monthly") - quarterView = inactiveTextStyle.Render("quarterly") - yearView = textStyle.Render("yearly") + yearView = activeTextStyle.Render("yearly") } return lipgloss.JoinVertical( From eda62f4fc3a79b88ba57e664dbb3215dd0c4bac8 Mon Sep 17 00:00:00 2001 From: Siddhanta <66236925+siddhantac@users.noreply.github.com> Date: Thu, 27 Jun 2024 22:48:54 +0800 Subject: [PATCH 3/3] refactored --- ui/period.go | 7 ++++--- ui/sort_mode.go | 18 +++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ui/period.go b/ui/period.go index 27b4202..de59322 100644 --- a/ui/period.go +++ b/ui/period.go @@ -31,8 +31,9 @@ func (p *Period) Update(msg tea.Msg) { } func (p *Period) View() string { - periodTitleStyle := sectionTitleStyle.Copy() - sectionTitle := periodTitleStyle.Render("PERIOD") + periodTitleStyle := sectionTitleStyle. + Copy(). + Render("PERIOD") inactiveTextStyle := lipgloss.NewStyle(). Foreground(theme.PrimaryForeground). @@ -60,7 +61,7 @@ func (p *Period) View() string { return lipgloss.JoinVertical( lipgloss.Right, - sectionTitle, + periodTitleStyle, weekView, monthView, quarterView, diff --git a/ui/sort_mode.go b/ui/sort_mode.go index d0e92cd..309a69f 100644 --- a/ui/sort_mode.go +++ b/ui/sort_mode.go @@ -5,29 +5,29 @@ import ( ) func sortingView(isSortByAmount bool) string { - sortTitleStyle := sectionTitleStyle.Copy() - sectionTitle := sortTitleStyle. + sortTitleStyle := sectionTitleStyle.Copy(). MarginTop(1). Render("SORT") inactiveTextStyle := lipgloss.NewStyle(). Foreground(theme.PrimaryForeground). MarginRight(2) - textStyle := lipgloss.NewStyle(). + activeTextStyle := lipgloss.NewStyle(). MarginRight(2) - var sortAmount, sortAccount string - if isSortByAmount { - sortAmount = textStyle.Render("amount") + var ( sortAccount = inactiveTextStyle.Render("account") + sortAmount = inactiveTextStyle.Render("amount") + ) + if isSortByAmount { + sortAmount = activeTextStyle.Render("amount") } else { - sortAmount = inactiveTextStyle.Render("amount") - sortAccount = textStyle.Render("account") + sortAccount = activeTextStyle.Render("account") } return lipgloss.JoinVertical( lipgloss.Right, - sectionTitle, + sortTitleStyle, sortAmount, sortAccount, )