Fix issues of sort by view

pull/281/head
Vuong 2 years ago
parent 08c7a026cc
commit 06c56b599a
No known key found for this signature in database
GPG Key ID: F4C603CC37B47A46

@ -289,11 +289,11 @@ func NewCointop(config *Config) (*Cointop, error) {
selectedChartRange: DefaultChartRange, selectedChartRange: DefaultChartRange,
shortcutKeys: DefaultShortcuts(), shortcutKeys: DefaultShortcuts(),
selectedView: CoinsView, selectedView: CoinsView,
page: 0,
perPage: int(perPage),
viewSorts: map[string]*sortConstraint{ viewSorts: map[string]*sortConstraint{
CoinsView: {DefaultSortBy, false}, CoinsView: {DefaultSortBy, false},
}, },
page: 0,
perPage: int(perPage),
portfolio: &Portfolio{ portfolio: &Portfolio{
Entries: make(map[string]*PortfolioEntry), Entries: make(map[string]*PortfolioEntry),
}, },

@ -89,7 +89,7 @@ func (ct *Cointop) Sort(sortCons *sortConstraint, list []*Coin, renderHeaders bo
// SortAsc sorts list of coins in ascending order // SortAsc sorts list of coins in ascending order
func (ct *Cointop) SortAsc() error { func (ct *Cointop) SortAsc() error {
log.Debug("SortAsc()") log.Debug("SortAsc()")
ct.State.viewSorts[ct.State.selectedView].sortDesc = true ct.State.viewSorts[ct.State.selectedView].sortDesc = false
ct.UpdateTable() ct.UpdateTable()
return nil return nil
} }

@ -269,7 +269,7 @@ func (ct *Cointop) SetSelectedView(viewName string) {
ct.State.lastSelectedView = ct.State.selectedView ct.State.lastSelectedView = ct.State.selectedView
ct.State.selectedView = viewName ct.State.selectedView = viewName
// init sort constraint for the view in case user travels it in the first time // init sort constraint for the view if it hasn't been seen before
if _, found := ct.State.viewSorts[viewName]; !found { if _, found := ct.State.viewSorts[viewName]; !found {
ct.State.viewSorts[viewName] = &sortConstraint{DefaultSortBy, false} ct.State.viewSorts[viewName] = &sortConstraint{DefaultSortBy, false}
} }

@ -217,11 +217,11 @@ func (ct *Cointop) UpdateTableHeader() error {
arrow := " " arrow := " "
colorfn := baseColor colorfn := baseColor
if !noSort { if !noSort {
corSortCons := ct.State.viewSorts[ct.State.selectedView] currentSortCons := ct.State.viewSorts[ct.State.selectedView]
if corSortCons.sortBy == col { if currentSortCons.sortBy == col {
colorfn = ct.colorscheme.TableHeaderColumnActiveSprintf() colorfn = ct.colorscheme.TableHeaderColumnActiveSprintf()
arrow = ArrowUp arrow = ArrowUp
if corSortCons.sortDesc { if currentSortCons.sortDesc {
arrow = ArrowDown arrow = ArrowDown
} }
} }

Loading…
Cancel
Save