Skip to content

Commit

Permalink
Added animation into sync screen
Browse files Browse the repository at this point in the history
  • Loading branch information
grrlopes committed Aug 23, 2023
1 parent 25e6c13 commit 9ac2223
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions entity/cmdmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/paginator"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/textinput"
"github.com/charmbracelet/bubbles/viewport"
"github.com/grrlopes/storydb/helper"
Expand Down Expand Up @@ -32,4 +33,5 @@ type CmdModel struct {
HomeKeys helper.Keymap
FinderKeys helper.Keymap
Help help.Model
Spinner spinner.Model
}
4 changes: 4 additions & 0 deletions ui/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/paginator"
"github.com/charmbracelet/bubbles/progress"
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/textinput"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -56,6 +57,8 @@ func NewHome(m *entity.CmdModel) *ModelHome {
txt.Width = 50
txt.Prompt = "Finder: "
h := help.New()
spin := spinner.New()
spin.Spinner = spinner.Jump

home := ModelHome{
home: entity.CmdModel{
Expand All @@ -73,6 +76,7 @@ func NewHome(m *entity.CmdModel) *ModelHome {
HomeKeys: helper.HotKeysHome,
FinderKeys: helper.HotKeysFinder,
Help: h,
Spinner: spin,
},
}
return &home
Expand Down
29 changes: 14 additions & 15 deletions ui/sync.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package ui

import (
"strings"
"fmt"
"time"

"github.com/charmbracelet/bubbles/progress"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
Expand Down Expand Up @@ -33,13 +32,17 @@ func syncUpdate(msg tea.Msg, m ModelHome) (*ModelHome, tea.Cmd) {
m.home.Viewport.SetContent(syncView(&m))
return &m, nil
case "enter":
choiceEntered = true
if m.home.StatusSyncScreen {
choiceEntered = true
cmd = syncTickCmd()
} else {
choiceEntered = false
}
m.home.StatusSyncScreen = false
return &m, syncTickCmd()
return &m, cmd
case "q":
if m.home.ActiveSyncScreen {
m.home.ActiveSyncScreen = false
m.home.ProgressSync = progress.NewModel(progress.WithDefaultGradient())
m.home.Viewport.SetContent(m.GetDataView())
choiceEntered = false
return &m, nil
Expand All @@ -48,16 +51,13 @@ func syncUpdate(msg tea.Msg, m ModelHome) (*ModelHome, tea.Cmd) {
case tea.WindowSizeMsg:
m.home.Viewport.Width = msg.Width
m.home.Viewport.Height = msg.Height
m.home.ProgressSync.Width = msg.Width - padding*2 - 4
if m.home.ProgressSync.Width > maxWidth {
m.home.ProgressSync.Width = maxWidth
}
m.home.Viewport.SetContent(syncView(&m))
case tickMsg:
// fposition := usecaseHistory.Execute()
cmd = m.home.Spinner.Tick
m.home.Viewport.SetContent(syncView(&m))
return &m, cmd
return &m, tea.Batch(syncTickCmd(), cmd)
}
m.home.Spinner, cmd = m.home.Spinner.Update(msg)
return &m, cmd
}

Expand All @@ -70,7 +70,7 @@ func syncView(m *ModelHome) string {
} else if choiceEntered {
okButton = ButtonDisableStyle.Render("Yes")
cancelButton = ButtonDisableStyle.Render("No, take me back")
} else {
} else if !choiceEntered {
okButton = ButtonStyle.Render("Yes")
cancelButton = ActiveButtonStyle.Render("No, take me back")
}
Expand All @@ -97,9 +97,8 @@ func syncView(m *ModelHome) string {
}

func syncProgressView(m *ModelHome) string {
pad := strings.Repeat(" ", padding)
return "\n" +
pad + "--------" + "\n"
sync := fmt.Sprintf("%s Syncing .....", m.home.Spinner.View())
return sync
}

func syncTickCmd() tea.Cmd {
Expand Down

0 comments on commit 9ac2223

Please sign in to comment.