-
Notifications
You must be signed in to change notification settings - Fork 0
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
PR: Phoenix
LiveView
Drag-and-Drop Example
#5
Conversation
Run the current examples with node Add lock package file to gitignore
- Create new phx app - Add Tailwind to the phoenix application
080d28d
to
c4f9743
Compare
I've added Tailwind to the Phoenix application with c4f9743 However the hot reload when changing a css class doesn't seem to work. I have to stop and restart the server to be able to see the Tailwind changes. @nelsonic when you have some time, do you mind to try this branch to see if changing a css Tailwind class automatically apply the new style on your browser. I'm not sure if it's a configuration issue on my machine or on the Phx application itself. |
@SimonLab remember to add the "watcher". Find the tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]} |
Yes I've added the watcher here: learn-alpine.js/config/dev.exs Lines 27 to 31 in c4f9743
That's why I'm not sure what the css is not compiled automatically when I changed a class |
Hmm ... that's strange. Let me try and run it on my |
@SimonLab I did: git checkout 'phoenix-example-#4'
mix deps.get
mix assets.deploy
mix s Works for me: tailwind-hot-reloading-working.mov |
Thanks for checking, I didn't run |
Weirdly hotreload works with Tailwind v3.18, however v3.2.0 or v3.2.1 doesn't change the UI on reload! I don't want to spend too much time on this specific issue, if it's working with 3.1.8 I'll continue with this and see later on if I can find what is the problem with v3.2 |
- hotreload doesn't seem to work with 3.2 so using 3.1.8
Add alpine.js cdn in root file Create button using Alpine to test everything still ok
Create item schema using phx.gen.live
@SimonLab yeah, it worked with |
Run mix format
Create index when new item created
Update modal form to create item
Update and remove unused tests
@SimonLab looking great so far. Thanks for the demo during standup. 👌 |
First attempt at drag and drop with vanilla js version
Drag and drop with javascript
It took me a bit of time to implement a solution using javascript: eeba5be My goal is now to see how to implement the vanilla js logic using Alpine.js.
|
use bg-red-100 to see moving item
Set background color when an element is moved
Use Alpine.js to drag and drop an item in a list
4572d5d
to
dfcebaa
Compare
Remove Tailwind and Petal Components to make the setup easier.
Read again the doc and make it easier to follow/implement
51d09b7
to
5bd6e18
Compare
@LuchoTurtle I've updated the documentation (you won't need to install Petal) and this should be easier to setup and follow but let me know if you still spot some issues, thanks |
I forgot to update the code to the latest version described in the doc. I'm going to do this soon! Thank for testing the PR! |
Finished going through the guide and got it working splendidly! Thank you @SimonLab ! I'll leave the code review to the pros 😅 |
3bffb9b
to
d93ba56
Compare
Update Phoenix app code to match the one describe in the markdown documentation
d93ba56
to
1144e64
Compare
<h1>Listing Items</h1> | ||
|
||
<%= if @live_action in [:new, :edit] do %> | ||
<.modal return_to={Routes.item_index_path(@socket, :index)}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SimonLab do we need to use a <.modal>
for creating new
items
? 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The modal is created automatically by Phoenix when running the phx.gen.live
command at https://github.com/dwyl/learn-alpine.js/blob/phoenix-example-%234/drag-and-drop.md#create-items
I thought about updating the way Phoenix creates the items however I didn't want to make the tutorial longer and preferred to focus on the drag and drop feature part itself.
Otherwise I can create another documentation file to explain how to create from scratch (without using the phx gen.live
command) the liveView structure for creating the items.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SimonLab thanks for clarifying that this was generated by phx.gen.live
. 👌
It's definitely concerning [to me] that someone in the Phoenix team 🤷♂️
thought it was "OK" to include modals in the default UX for creating new content. 🤦♂️
Modals are not even remotely "OK"; they're a UX anti-pattern 😢
and a major red flag of lazy design. 🔴
For the purposes of this example/spike, 🧑💻
the objective is to demo drag-and-drop 🐉
and you have achieved that. ✅
In terms of our scarce/valuable time we don't need to spend any more on this. 💸
I've made a note to write about it: dwyl/product-ux-research#38 📝
We will completely avoid them in our App
. 🙅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SimonLab excellent code and docs!
Would be good to add some tests as the coverage is quite low ...
mix c
Coverage:
----------------
COV FILE LINES RELEVANT MISSED
0.0% lib/app.ex 9 0 0
75.0% lib/app/application.ex 36 4 1
0.0% lib/app/repo.ex 5 0 0
61.1% lib/app/tasks.ex 146 18 7
100.0% lib/app/tasks/item.ex 18 2 0
0.0% lib/app_web.ex 110 1 1
0.0% lib/app_web/controllers/page_controller. 7 1 1
0.0% lib/app_web/endpoint.ex 46 0 0
41.7% lib/app_web/live/item_live/form_componen 55 12 7
33.3% lib/app_web/live/item_live/index.ex 107 18 12
0.0% lib/app_web/live/item_live/show.ex 21 5 5
90.0% lib/app_web/live/live_helpers.ex 60 10 1
37.5% lib/app_web/router.ex 32 8 5
80.0% lib/app_web/telemetry.ex 71 5 1
25.0% lib/app_web/views/error_helpers.ex 30 4 3
100.0% lib/app_web/views/error_view.ex 16 1 0
0.0% lib/app_web/views/layout_view.ex 7 0 0
0.0% lib/app_web/views/page_view.ex 3 0 0
100.0% test/support/conn_case.ex 38 2 0
57.1% test/support/data_case.ex 58 7 3
100.0% test/support/fixtures/tasks_fixtures.ex 20 2 0
[TOTAL] 53.0%
----------------
Some of these files can be ignored, but others will need to have tests. 💭
We can add a chore
to the backlog to create these tests. 🙏
and ideally write very clear docs for the tests 📝
because this feature will be "core" to our App
. 📱
Create Phoenix application
see: #4