Skip to content

Commit

Permalink
Included 'state' for sync screen
Browse files Browse the repository at this point in the history
  • Loading branch information
grrlopes committed Jul 7, 2023
1 parent edc6e35 commit 249fb14
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions ui/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ func NewHome(m *entity.Command) *ModelHome {

home := ModelHome{
home: entity.Command{
Content: m.Content,
Ready: false,
Viewport: viewport.Model{},
PageTotal: m.PageTotal,
Pagination: &p,
Count: count,
Content: m.Content,
Ready: false,
Viewport: viewport.Model{},
PageTotal: m.PageTotal,
Pagination: &p,
Count: count,
ActiveSyncScreen: false,
StatusSyncScreen: false,
},
}
return &home
Expand All @@ -58,7 +60,34 @@ func (m ModelHome) FooterView() string {
return lipgloss.JoinHorizontal(lipgloss.Center, line)
}

func (m ModelHome) update2(msg tea.Msg) (*ModelHome, tea.Cmd) {
var cmd tea.Cmd

switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "left":
m.home.ActiveSyncScreen = true
m.home.Viewport.SetContent(ConfirmationView(m))
return &m, cmd
case "right":
m.home.ActiveSyncScreen = false
m.home.Viewport.SetContent(ConfirmationView(m))
return &m, cmd
case "enter":
m.home.StatusSyncScreen = false
m.home.Viewport.SetContent(m.GetDataView())
return &m, cmd
}
}
return &m, cmd
}

func (m ModelHome) Update(msg tea.Msg) (*ModelHome, tea.Cmd) {
if m.home.StatusSyncScreen {
m.home.Ready = true
return m.update2(msg)
}
var cmd tea.Cmd

switch msg := msg.(type) {
Expand All @@ -79,7 +108,10 @@ func (m ModelHome) Update(msg tea.Msg) (*ModelHome, tea.Cmd) {
case "ctrl+g":
m.home.Cursor = m.home.PageTotal - 1
case "s":
usecaseHistory.Execute()
m.home.StatusSyncScreen = true
m.home.ActiveSyncScreen = true
m.home.Viewport.SetContent(ConfirmationView(m))
return &m, cmd
case "ctrl+u":
m.home.Cursor = 0
case "enter":
Expand All @@ -103,13 +135,12 @@ func (m ModelHome) Update(msg tea.Msg) (*ModelHome, tea.Cmd) {

func (m ModelHome) View() string {
view := lipgloss.NewStyle()
content := lipgloss.NewStyle()
content := lipgloss.NewStyle().Padding(1, 2, 1, 2)
if !m.home.Ready {
return "\n Loading..."
}

return view.Render(
m.HeaderView()) + "\n" +
return view.Render(m.HeaderView()) + "\n" +
content.Render(m.home.Viewport.View()) + "\n" +
m.FooterView() + "\n" +
m.paginationView()
Expand Down

0 comments on commit 249fb14

Please sign in to comment.