Skip to content

Commit

Permalink
ref(ui): go back msg
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Nov 15, 2022
1 parent f65e532 commit c7a9618
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
36 changes: 21 additions & 15 deletions ui/pages/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/charmbracelet/soft-serve/config"
ggit "github.com/charmbracelet/soft-serve/git"
"github.com/charmbracelet/soft-serve/ui/common"
"github.com/charmbracelet/soft-serve/ui/components/footer"
"github.com/charmbracelet/soft-serve/ui/components/statusbar"
"github.com/charmbracelet/soft-serve/ui/components/tabs"
"github.com/charmbracelet/soft-serve/ui/git"
Expand Down Expand Up @@ -199,18 +200,23 @@ func (r *Repo) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
if r.selectedRepo != nil {
cmds = append(cmds, r.updateStatusBarCmd)
switch msg := msg.(type) {
case tea.MouseMsg:
switch msg.Type {
case tea.MouseLeft:
id := fmt.Sprintf("%s-url", r.selectedRepo.Repo())
if r.common.Zone.Get(id).InBounds(msg) {
cmds = append(cmds, r.copyUrlCmd())
}
case tea.MouseRight:
if r.common.Zone.Get("repo-main").InBounds(msg) {
cmds = append(cmds, backCmd)
}
urlID := fmt.Sprintf("%s-url", r.selectedRepo.Repo())
if msg, ok := msg.(tea.MouseMsg); ok && r.common.Zone.Get(urlID).InBounds(msg) {
cmds = append(cmds, r.copyURLCmd())
}
}
switch msg := msg.(type) {
case tea.MouseMsg:
switch msg.Type {
case tea.MouseLeft:
switch {
case r.common.Zone.Get("repo-help").InBounds(msg):
cmds = append(cmds, footer.ToggleFooterCmd)
}
case tea.MouseRight:
switch {
case r.common.Zone.Get("repo-main").InBounds(msg):
cmds = append(cmds, backCmd)
}
}
}
Expand Down Expand Up @@ -285,12 +291,12 @@ func (r *Repo) View() string {
Height(r.common.Height - hm)
main := r.common.Zone.Mark(
"repo-main",
r.panes[r.activeTab].View(),
mainStyle.Render(r.panes[r.activeTab].View()),
)
view := lipgloss.JoinVertical(lipgloss.Top,
r.headerView(),
r.tabs.View(),
mainStyle.Render(main),
main,
r.statusbar.View(),
)
return s.Render(view)
Expand Down Expand Up @@ -375,7 +381,7 @@ func (r *Repo) updateModels(msg tea.Msg) tea.Cmd {
return tea.Batch(cmds...)
}

func (r *Repo) copyUrlCmd() tea.Cmd {
func (r *Repo) copyURLCmd() tea.Cmd {
r.copyURL = time.Now()
return tea.Batch(
func() tea.Msg {
Expand Down
6 changes: 3 additions & 3 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
ui.showFooter = true
}
case tea.MouseMsg:
if msg.Type == tea.MouseLeft {
switch msg.Type {
case tea.MouseLeft:
switch {
case ui.common.Zone.Get("repo-help").InBounds(msg),
ui.common.Zone.Get("footer").InBounds(msg):
case ui.common.Zone.Get("footer").InBounds(msg):
cmds = append(cmds, footer.ToggleFooterCmd)
}
}
Expand Down

0 comments on commit c7a9618

Please sign in to comment.