Closed rusinikita closed 6 months ago
I can try help with it but as i see it not obvious now. Choose returns play.New and i dont know how to return to the previous view
I'll look and write you instructions later today
I've found solution. Run play.New with function callback that returns choose.Update.
@mortum5 best option is something like that in (m model) Update
case key.Matches(msg, m.b.Back):
chooseModel := choose.New()
commands := tea.Sequence(chooseModel.Init(), func() tea.Msg {
return m.w // pass tea.WindowSizeMsg to sync window size
})
return chooseModel, commands
Here is navigation idea
sequenceDiagram
participant App as App event loop
App->>+Choose: Show Choose
Choose-->>Choose: Challenge selected
Choose-->>-App: Play model
App->>+Play: Show Play
Play-->>Play: Back pressed
Play-->>-App: Choose model
App->>+Choose: Show Choose
So, you need to define key bindings, add navigation as in code sample, and check it works (check window resize as well).
Important: check if b/⌫ - back
showed in help message on screen bottom (when h
pressed)
Your solution works as alternative. But there is no need for callbacks.
You can pass Choose model instance in Play and return it in Play.Update. But you still need to sync window size.
Downside is state coupling. So I think creating choose.New instance is better.
Mmm. I forgot about import cycle. @mortum5 so, create PR, let's see your solution.
Yes, I tried to use a new select instance first, but ran into a problem with the imports
But you are right about window size. I will think how to sync them.
P.S. Found, just override msg
Create PR draft, I can help
Add 'b/backspace' button handling to return to list