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

Step by step guide for creating the stopwatch #1

Closed
SimonLab opened this issue Jun 13, 2022 · 10 comments
Closed

Step by step guide for creating the stopwatch #1

SimonLab opened this issue Jun 13, 2022 · 10 comments
Assignees
Labels
epic A feature idea that is large enough to require a whole sprint (5 days) and has smaller sub-issues. priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished

Comments

@SimonLab
Copy link
Member

Create the Elixir/Phoenix version of https://github.com/dwyl/stopwatch using LiveView.

  • Use mount to initialise the timer state and start :timer on server
  • Use handle_info to list to the timer event
  • Send new timer state to client

Inspired by: https://elixirforum.com/t/livecomponent-updating-itself-at-regular-intervals/37047/8

@SimonLab SimonLab added the epic A feature idea that is large enough to require a whole sprint (5 days) and has smaller sub-issues. label Jun 13, 2022
@SimonLab SimonLab self-assigned this Jun 13, 2022
@SimonLab SimonLab added the priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished label Jun 13, 2022
@SimonLab SimonLab added this to To do in Simon's list via automation Jun 13, 2022
@SimonLab SimonLab moved this from To do to In progress in Simon's list Jun 13, 2022
@SimonLab
Copy link
Member Author

Create new Phoenix stopwatch app ⏱️

Run mix phx.new stopwatch --no-ecto --no-mailer --no-dashboard --no-gettext
Run mix help phx.new to see the documentation and list of options for phx.new command
Install dependencies, then cd stopwatch and make sure the tests are passing mix test and the application is running mix phx.server

Create liveview structure:

  • Create live folder for liveview controllers: mkdir lib/stopwatch_web/live
  • Create controller for liveview: touch lib/stopwatch_web/live/stopwatch_live.ex This is where the liveview logic happen
  • Create view view file for liveview templates: touch lib/stopwatch_web/views/stopwatch_view.ex
  • Create new template folder for liveview templates: mkdir lib/stopwatch_web/templates/stopwatch
  • Finally create the template file itself: touch lib/stopwatch_web/templates/stopwatch/stopwatch.html.heex

See doc about colocating section

Update created files above to make liveview magic happen

@nelsonic
Copy link
Member

@SimonLab have you looked at using Alpine.js for the counter bit?
If not, I was thinking of adding a basic stopwatch in Alpine + Tailwind now.

@SimonLab
Copy link
Member Author

I've just finished my spike on using only liveView for the timer:
image

And was going to look at creating a section in the Readme using liveView + js (can be Alpine). The block button simulate latency on the server side with Process.sleep, this to show that the timer can be blocked if there are events on the server blocking the timer messages hence using js for incrementing the timer.

But I'll start writing the documentation of the liveview version first so you're welcome to start on the Alpine + tailwind timer

@nelsonic
Copy link
Member

@SimonLab OK, cool. gonna take a look at this: dwyl/learn-alpine.js#2

@SimonLab
Copy link
Member Author

SimonLab commented Jun 15, 2022

I've created a draft PR which initialised the Phoenix application and I've updated the Readme with the steps to create the stopwatch (I've deleted by error the readme containing the steps, I need to rewrite this!), still need to:

  • Follow the steps on the Readme and update the Phoenix code
  • Add Github CI to run the tests on Github
  • Deploy the application on Fly
  • Update the tests

@SimonLab SimonLab added the in-progress An issue or pull request that is being worked on by the assigned person label Jun 15, 2022
@SimonLab
Copy link
Member Author

SimonLab commented Jun 15, 2022

Application deployed at https://liveview-stopwatch.fly.dev/

@nelsonic
Copy link
Member

@nelsonic
Copy link
Member

Pretty confident I/we could integrate Alpine.js into the LiveView stopwatch
and only send the start|stop time and events to the server for synch to connected clients.

@SimonLab SimonLab moved this from In progress to Awaiting Feedback/Review in Simon's list Jun 16, 2022
@SimonLab SimonLab added awaiting-review An issue or pull request that needs to be reviewed and removed in-progress An issue or pull request that is being worked on by the assigned person labels Jun 16, 2022
@nelsonic nelsonic moved this from Awaiting Feedback/Review to Done in Simon's list Jun 17, 2022
@nelsonic nelsonic added this to More ToDo ThanCanEver Be Done in Nelson's List via automation Jun 17, 2022
@nelsonic nelsonic moved this from More ToDo ThanCanEver Be Done to Done in Nelson's List Jun 17, 2022
@nelsonic
Copy link
Member

@SimonLab your PR #2 is merged. Anything else to do for this issue? 💭

@SimonLab
Copy link
Member Author

I think we can close this issue now and focus on #3

@SimonLab SimonLab removed the awaiting-review An issue or pull request that needs to be reviewed label Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic A feature idea that is large enough to require a whole sprint (5 days) and has smaller sub-issues. priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished
Projects
Nelson's List
  
Done
Development

No branches or pull requests

2 participants