repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
946bdf5
parent
f45122a
author
Eric Bower
date
2024-05-17 16:08:52 +0000 UTC
fix(tui): update models when resizing
1 files changed,  +14, -16
M tui/ui.go
+14, -16
 1@@ -83,6 +83,19 @@ func (m *UI) Init() tea.Cmd {
 2 	return nil
 3 }
 4 
 5+func (m *UI) updateModels(msg tea.Msg) tea.Cmd {
 6+	cmds := []tea.Cmd{}
 7+	for i, page := range m.pages {
 8+		if page == nil {
 9+			continue
10+		}
11+		nm, cmd := page.Update(msg)
12+		m.pages[i] = nm
13+		cmds = append(cmds, cmd)
14+	}
15+	return tea.Batch(cmds...)
16+}
17+
18 func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
19 	var cmds []tea.Cmd
20 
21@@ -90,6 +103,7 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
22 	case tea.WindowSizeMsg:
23 		m.shared.Width = msg.Width
24 		m.shared.Height = msg.Height
25+		return m, m.updateModels(msg)
26 
27 	case tea.KeyMsg:
28 		switch msg.Type {
29@@ -166,19 +180,3 @@ func (m *UI) View() string {
30 	)
31 	return m.shared.Styles.App.Render(str)
32 }
33-
34-/*
35-TODO: I dont think we need this but keeping for a bit
36-func (m *UI) updateModels(msg tea.Msg) tea.Cmd {
37-	cmds := []tea.Cmd{}
38-	for i, page := range m.pages {
39-		if page == nil {
40-			continue
41-		}
42-		nm, cmd := page.Update(msg)
43-		m.pages[i] = nm
44-		cmds = append(cmds, cmd)
45-	}
46-	return tea.Batch(cmds...)
47-}
48-*/