fix(ui): update log items when toggling help footer

Ayman Bagabas created

Change summary

ui/components/footer/footer.go |  8 ++++++++
ui/pages/repo/log.go           |  3 +++
ui/ui.go                       | 12 +++++++-----
3 files changed, 18 insertions(+), 5 deletions(-)

Detailed changes

ui/components/footer/footer.go 🔗

@@ -8,6 +8,9 @@ import (
 	"github.com/charmbracelet/soft-serve/ui/common"
 )
 
+// ToggleFooterMsg is a message sent to show/hide the footer.
+type ToggleFooterMsg struct{}
+
 // Footer is a Bubble Tea model that displays help and other info.
 type Footer struct {
 	common common.Common
@@ -83,3 +86,8 @@ func (f *Footer) SetShowAll(show bool) {
 func (f *Footer) Height() int {
 	return lipgloss.Height(f.View())
 }
+
+// ToggleFooterCmd sends a ToggleFooterMsg to show/hide the help footer.
+func ToggleFooterCmd() tea.Msg {
+	return ToggleFooterMsg{}
+}

ui/pages/repo/log.go 🔗

@@ -12,6 +12,7 @@ import (
 	"github.com/charmbracelet/lipgloss"
 	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/selector"
 	"github.com/charmbracelet/soft-serve/ui/components/viewport"
 	"github.com/charmbracelet/soft-serve/ui/git"
@@ -274,6 +275,8 @@ func (l *Log) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 			// stop loading after setting the viewport content
 			l.stopLoading(),
 		)
+	case footer.ToggleFooterMsg:
+		cmds = append(cmds, l.updateCommitsCmd)
 	case tea.WindowSizeMsg:
 		if l.selectedCommit != nil && l.currentDiff != nil {
 			l.vp.SetContent(

ui/ui.go 🔗

@@ -184,11 +184,7 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 				// Always show the footer on error.
 				ui.showFooter = ui.footer.ShowAll()
 			case key.Matches(msg, ui.common.KeyMap.Help):
-				ui.footer.SetShowAll(!ui.footer.ShowAll())
-				// Show the footer when on repo page and shot all help.
-				if ui.error == nil && ui.activePage == repoPage {
-					ui.showFooter = !ui.showFooter
-				}
+				cmds = append(cmds, footer.ToggleFooterCmd)
 			case key.Matches(msg, ui.common.KeyMap.Quit):
 				return ui, tea.Quit
 			case ui.activePage == repoPage && key.Matches(msg, ui.common.KeyMap.Back):
@@ -197,6 +193,12 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 				ui.showFooter = true
 			}
 		}
+	case footer.ToggleFooterMsg:
+		ui.footer.SetShowAll(!ui.footer.ShowAll())
+		// Show the footer when on repo page and shot all help.
+		if ui.error == nil && ui.activePage == repoPage {
+			ui.showFooter = !ui.showFooter
+		}
 	case repo.RepoMsg:
 		ui.activePage = repoPage
 		// Show the footer on repo page if show all is set.