Move "stashed only" flag from the package-level into the model

This commit is contained in:
Christian Rocha 2020-10-17 17:39:43 -04:00 committed by Christian Rocha
parent 5847578f42
commit e73190a217
3 changed files with 15 additions and 18 deletions

View file

@ -262,9 +262,7 @@ func runTUI(stashedOnly bool) error {
}
cfg.ShowAllFiles = showAllFiles
if stashedOnly {
cfg.StashedOnly = true
}
cfg.StashedOnly = stashedOnly
// Run Bubble Tea program
p := ui.NewProgram(style, cfg)

View file

@ -72,6 +72,7 @@ const (
type stashModel struct {
cc *charm.Client
cfg *Config
authStatus authStatus
state stashState
err error
@ -198,7 +199,7 @@ func (m *stashModel) hideStatusMessage() {
// INIT
func newStashModel(as authStatus) stashModel {
func newStashModel(cfg *Config, as authStatus) stashModel {
sp := spinner.NewModel()
sp.Frames = spinner.Line
sp.ForegroundColor = common.SpinnerColor.String()
@ -217,6 +218,7 @@ func newStashModel(as authStatus) stashModel {
ni.Focus()
m := stashModel{
cfg: cfg,
authStatus: as,
spinner: sp,
noteInput: ni,
@ -278,7 +280,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
}
case spinner.TickMsg:
condition := !m.loaded.done(stashedOnly) ||
condition := !m.loaded.done(m.cfg.StashedOnly) ||
m.loadingFromNetwork ||
m.state == stashStateLoadingDocument ||
len(m.filesStashing) > 0 ||
@ -424,7 +426,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
m.filesStashing[md.localPath] = struct{}{}
cmds = append(cmds, stashDocument(m.cc, *md))
if m.loaded.done(stashedOnly) && !m.spinner.Visible() {
if m.loaded.done(m.cfg.StashedOnly) && !m.spinner.Visible() {
m.spinner.Start()
cmds = append(cmds, spinner.Tick(m.spinner))
}
@ -568,7 +570,7 @@ func stashView(m stashModel) string {
case stashStateReady, stashStateSettingNote, stashStatePromptDelete:
loadingIndicator := ""
if !m.loaded.done(stashedOnly) || m.loadingFromNetwork || m.spinner.Visible() {
if !m.loaded.done(m.cfg.StashedOnly) || m.loadingFromNetwork || m.spinner.Visible() {
loadingIndicator = spinner.View(m.spinner)
}
@ -637,10 +639,10 @@ func glowLogoView(text string) string {
}
func stashHeaderView(m stashModel) string {
loading := !m.loaded.done(stashedOnly)
loading := !m.loaded.done(m.cfg.StashedOnly)
noMarkdowns := len(m.markdowns) == 0
if m.authStatus == authFailed && stashedOnly {
if m.authStatus == authFailed && m.cfg.StashedOnly {
return common.Subtle("Cant load stash. Are you offline?")
}
@ -651,7 +653,7 @@ func stashHeaderView(m stashModel) string {
// Still loading. We haven't found files, stashed items, or news yet.
if loading && noMarkdowns {
if stashedOnly {
if m.cfg.StashedOnly {
return common.Subtle("Loading your stash...")
} else {
return common.Subtle("Looking for stuff...") + maybeOffline
@ -663,7 +665,7 @@ func stashHeaderView(m stashModel) string {
// Loading's finished and all we have is news.
if !loading && localItems == 0 && stashedItems == 0 {
if stashedOnly {
if m.cfg.StashedOnly {
return common.Subtle("No stashed markdown files found.") + maybeOffline
} else {
return common.Subtle("No local or stashed markdown files found.") + maybeOffline

View file

@ -28,7 +28,6 @@ var (
config Config
glowLogoTextColor = common.Color("#ECFD65")
debug = false // true if we're logging to a file, in which case we'll log more stuff
stashedOnly = false
)
// Config contains TUI-specific configuration.
@ -135,7 +134,7 @@ const (
)
type model struct {
cfg Config
cfg *Config
cc *charm.Client
authStatus authStatus
keygenState keygenState
@ -164,7 +163,7 @@ func (m *model) unloadDocument() []tea.Cmd {
if m.pager.viewport.HighPerformanceRendering {
batch = append(batch, tea.ClearScrollArea)
}
if !m.stash.loaded.done(stashedOnly) || m.stash.loadingFromNetwork {
if !m.stash.loaded.done(m.cfg.StashedOnly) || m.stash.loadingFromNetwork {
batch = append(batch, spinner.Tick(m.stash.spinner))
}
return batch
@ -189,16 +188,14 @@ func initialize(cfg Config, style string) func() (tea.Model, tea.Cmd) {
}
}
stashedOnly = cfg.StashedOnly
m := model{
cfg: cfg,
cfg: &cfg,
state: stateShowStash,
authStatus: authConnecting,
keygenState: keygenUnstarted,
}
m.pager = newPagerModel(m.authStatus, style)
m.stash = newStashModel(m.authStatus)
m.stash = newStashModel(&cfg, m.authStatus)
cmds := []tea.Cmd{
newCharmClient,