Skip to content
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

I want return back to challenge list without app restart #2

Closed
rusinikita opened this issue Oct 7, 2023 · 9 comments · Fixed by #11
Closed

I want return back to challenge list without app restart #2

rusinikita opened this issue Oct 7, 2023 · 9 comments · Fixed by #11
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@rusinikita
Copy link
Owner

Add 'b/backspace' button handling to return to list

@rusinikita rusinikita added enhancement New feature or request good first issue Good for newcomers labels Oct 7, 2023
@mortum5
Copy link
Contributor

mortum5 commented May 3, 2024

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

@rusinikita
Copy link
Owner Author

I'll look and write you instructions later today

@mortum5
Copy link
Contributor

mortum5 commented May 3, 2024

I've found solution. Run play.New with function callback that returns choose.Update.

@rusinikita
Copy link
Owner Author

rusinikita commented May 3, 2024

@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
Loading

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)

@rusinikita
Copy link
Owner Author

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.

@rusinikita
Copy link
Owner Author

Mmm. I forgot about import cycle. @mortum5 so, create PR, let's see your solution.

@mortum5
Copy link
Contributor

mortum5 commented May 3, 2024

Yes, I tried to use a new select instance first, but ran into a problem with the imports

@mortum5
Copy link
Contributor

mortum5 commented May 3, 2024

But you are right about window size. I will think how to sync them.

P.S. Found, just override msg

@rusinikita
Copy link
Owner Author

Create PR draft, I can help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants