fix(tui): update with review

This commit is contained in:
lhpqaq
2026-02-16 00:24:25 +08:00
parent 0a2555b0f3
commit 2c8821891c
6 changed files with 197 additions and 163 deletions

View File

@@ -103,38 +103,7 @@ func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "L":
ToggleLocale()
a.tabs = TabNames()
// Broadcast locale change to ALL tabs so each re-renders
var cmds []tea.Cmd
var cmd tea.Cmd
a.dashboard, cmd = a.dashboard.Update(localeChangedMsg{})
if cmd != nil {
cmds = append(cmds, cmd)
}
a.config, cmd = a.config.Update(localeChangedMsg{})
if cmd != nil {
cmds = append(cmds, cmd)
}
a.auth, cmd = a.auth.Update(localeChangedMsg{})
if cmd != nil {
cmds = append(cmds, cmd)
}
a.keys, cmd = a.keys.Update(localeChangedMsg{})
if cmd != nil {
cmds = append(cmds, cmd)
}
a.oauth, cmd = a.oauth.Update(localeChangedMsg{})
if cmd != nil {
cmds = append(cmds, cmd)
}
a.usage, cmd = a.usage.Update(localeChangedMsg{})
if cmd != nil {
cmds = append(cmds, cmd)
}
a.logs, cmd = a.logs.Update(localeChangedMsg{})
if cmd != nil {
cmds = append(cmds, cmd)
}
return a, tea.Batch(cmds...)
return a.broadcastToAllTabs(localeChangedMsg{})
case "tab":
prevTab := a.activeTab
a.activeTab = (a.activeTab + 1) % len(a.tabs)
@@ -278,3 +247,39 @@ func Run(port int, secretKey string, hook *LogHook, output io.Writer) error {
_, err := p.Run()
return err
}
func (a App) broadcastToAllTabs(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmds []tea.Cmd
var cmd tea.Cmd
a.dashboard, cmd = a.dashboard.Update(msg)
if cmd != nil {
cmds = append(cmds, cmd)
}
a.config, cmd = a.config.Update(msg)
if cmd != nil {
cmds = append(cmds, cmd)
}
a.auth, cmd = a.auth.Update(msg)
if cmd != nil {
cmds = append(cmds, cmd)
}
a.keys, cmd = a.keys.Update(msg)
if cmd != nil {
cmds = append(cmds, cmd)
}
a.oauth, cmd = a.oauth.Update(msg)
if cmd != nil {
cmds = append(cmds, cmd)
}
a.usage, cmd = a.usage.Update(msg)
if cmd != nil {
cmds = append(cmds, cmd)
}
a.logs, cmd = a.logs.Update(msg)
if cmd != nil {
cmds = append(cmds, cmd)
}
return a, tea.Batch(cmds...)
}