From 96cab2b405fe73f9e564e5c2fb7311f5714d35f6 Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Tue, 2 Jul 2019 00:58:23 -0700 Subject: [PATCH] Add chart loading label --- cointop/chart.go | 19 +++++++++++++++++++ .../common/api/impl/coingecko/coingecko.go | 2 +- cointop/portfolio.go | 3 +++ cointop/table.go | 6 +++--- cointop/view.go | 8 +++++++- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/cointop/chart.go b/cointop/chart.go index a1870d1..e6c4fc7 100644 --- a/cointop/chart.go +++ b/cointop/chart.go @@ -92,6 +92,7 @@ func (ct *Cointop) UpdateChart() error { } } + ct.update(func() { if ct.Views.Chart.Backing() == nil { return @@ -108,6 +109,7 @@ func (ct *Cointop) ChartPoints(symbol string, name string) error { maxX := ct.maxTableWidth - 3 chartPointsLock.Lock() defer chartPointsLock.Unlock() + // TODO: not do this (SoC) go ct.updateMarketbar() @@ -209,6 +211,7 @@ func (ct *Cointop) PortfolioChart() error { maxX := ct.maxTableWidth - 3 chartPointsLock.Lock() defer chartPointsLock.Unlock() + // TODO: not do this (SoC) go ct.updateMarketbar() @@ -374,7 +377,23 @@ func (ct *Cointop) ToggleCoinChart() error { ct.State.selectedCoin = highlightedcoin } + go ct.ShowChartLoader() go ct.UpdateChart() go ct.updateMarketbar() return nil } + +// ShowChartLoader shows chart loading indicator +func (ct *Cointop) ShowChartLoader() error { + ct.update(func() { + if ct.Views.Chart.Backing() == nil { + return + } + + content := "\n\nLoading..." + ct.Views.Chart.Backing().Clear() + fmt.Fprint(ct.Views.Chart.Backing(), ct.colorscheme.Chart(content)) + }) + + return nil +} diff --git a/cointop/common/api/impl/coingecko/coingecko.go b/cointop/common/api/impl/coingecko/coingecko.go index bf0dcf0..3c20dda 100644 --- a/cointop/common/api/impl/coingecko/coingecko.go +++ b/cointop/common/api/impl/coingecko/coingecko.go @@ -149,7 +149,7 @@ func (s *Service) GetAllCoinData(convert string, ch chan []apitypes.Coin) error func (s *Service) GetCoinGraphData(symbol, name string, start, end int64) (apitypes.CoinGraph, error) { ret := apitypes.CoinGraph{} days := strconv.Itoa(util.CalcDays(start, end)) - chart, err := s.client.CoinsIDMarketChart(strings.ToLower(name), "usd", days) + chart, err := s.client.CoinsIDMarketChart(util.NameToSlug(name), "usd", days) if err != nil { return ret, err } diff --git a/cointop/portfolio.go b/cointop/portfolio.go index ae0e7ac..706df13 100644 --- a/cointop/portfolio.go +++ b/cointop/portfolio.go @@ -23,6 +23,7 @@ func NewPortfolioUpdateMenuView() *PortfolioUpdateMenuView { func (ct *Cointop) togglePortfolio() error { ct.State.filterByFavorites = false ct.State.portfolioVisible = !ct.State.portfolioVisible + go ct.UpdateChart() go ct.updateTable() return nil } @@ -30,6 +31,7 @@ func (ct *Cointop) togglePortfolio() error { func (ct *Cointop) toggleShowPortfolio() error { ct.State.filterByFavorites = false ct.State.portfolioVisible = true + go ct.UpdateChart() go ct.updateTable() return nil } @@ -39,6 +41,7 @@ func (ct *Cointop) togglePortfolioUpdateMenu() error { if ct.State.portfolioUpdateMenuVisible { return ct.showPortfolioUpdateMenu() } + return ct.hidePortfolioUpdateMenu() } diff --git a/cointop/table.go b/cointop/table.go index 52ffb36..2a748a9 100644 --- a/cointop/table.go +++ b/cointop/table.go @@ -43,6 +43,8 @@ func tableColumnOrder() []string { } } +const dots = "..." + // RefreshTable refreshes the table func (ct *Cointop) RefreshTable() error { maxX := ct.width() @@ -74,7 +76,6 @@ func (ct *Cointop) RefreshTable() error { color24h = ct.colorscheme.TableColumnChangeDown } name := coin.Name - dots := "..." star := " " rank := fmt.Sprintf("%s%v", star, ct.colorscheme.TableRow(fmt.Sprintf("%6v ", coin.Rank))) if len(name) > 20 { @@ -143,7 +144,6 @@ func (ct *Cointop) RefreshTable() error { color7d = ct.colorscheme.TableColumnChangeDown } name := coin.Name - dots := "..." star := ct.colorscheme.TableRow(" ") if coin.Favorite { star = ct.colorscheme.TableRowFavorite("*") @@ -312,7 +312,7 @@ func (ct *Cointop) RowLinkShort() string { path = parts[len(parts)-1] } - return fmt.Sprintf("http://%s/.../%s", host, path) + return fmt.Sprintf("http://%s/%s/%s", host, dots, path) } return "" diff --git a/cointop/view.go b/cointop/view.go index d955be9..642f895 100644 --- a/cointop/view.go +++ b/cointop/view.go @@ -36,12 +36,18 @@ func (view *View) SetBacking(gocuiView *gocui.View) { view.backing = gocuiView } -// Height returns thejview height +// Height returns the view height func (view *View) Height() int { _, h := view.backing.Size() return h } +// Width returns the view width +func (view *View) Width() int { + w, _ := view.backing.Size() + return w +} + // Name returns the view's name func (view *View) Name() string { return view.name