-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I determine current page? #19
Comments
🤖 AI Assistant Analysis To detect and trigger a message when switching tabs in the Skeleton library, you can leverage the Detecting Tab Switches
func (m *YourModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case skeleton.IAMActivePage:
// This block is called every time the tab is switched
fmt.Println("Tab switched to:", m.skeleton.GetActivePage())
// Perform any custom actions when tab is switched
}
return m, nil
} Practical Exampletype YourModel struct {
skeleton *skeleton.Skeleton
currentTabKey string
}
func (m *YourModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case skeleton.IAMActivePage:
newTabKey := m.skeleton.GetActivePage()
if m.currentTabKey != newTabKey {
fmt.Printf("Switched from %s to %s\n", m.currentTabKey, newTabKey)
m.currentTabKey = newTabKey
// Optional: Perform tab-specific initialization
switch newTabKey {
case "first_tab":
// Do something specific for first tab
case "second_tab":
// Do something specific for second tab
}
}
}
return m, nil
} Advanced Tab Switch Handling
Best Practices
Triggering Custom CommandsIf you want to trigger a custom command on tab switch: func (m *YourModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case skeleton.IAMActivePage:
return m, tea.Batch(
m.loadTabData(),
m.updateTabMetrics(),
)
}
return m, nil
}
func (m *YourModel) loadTabData() tea.Cmd {
return func() tea.Msg {
// Perform async data loading for the new tab
return nil
}
} Limitations and Considerations
This analysis was performed by Issue Assistant. If you have any questions, please contact the repository maintainers. |
🏷️ AI Label Analysis I've added the following labels to this issue:
Explanation: This label analysis was performed by Issue Assistant. If you have any questions, please contact the repository maintainers. |
How can I learn if I switch the tab? I want to trigger a message every tab switch.
The text was updated successfully, but these errors were encountered: