Programming Phoenix LiveView: B3.0 (page 27)

I tried to do the exercise for the basic LiveView “game”.

One part is:
Show a restart message and button when the user wins. Hint: you might want to check out the live_patch/28 function to help you build that button

Several things were not clear to me:

  • Should the success message and the Restart-Button be displayed in a new LiveView (CorrectLiveVive) or should I use the existing LiveView (WrongLiveView)?

I decided to use the existing LiveView.
As I had to conditionally render the view for the success-case and the wrong-case,
I added another state (answer_guessed Boolean) to the socket.

This allowed me to use this state to conditionally include the “live_patch”-method inside the render-function for the success case.

I then realized, I had to implement the “handle_params”-method correctly.

See: pento/wrong_live.ex at master · Chrichton/pento · GitHub

I am asking: Is there an easier way to solve this exercise?

Thank you for your reply, Heiko