-
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
391: Use importmaps and hotwire #395
Conversation
a39a728
to
1ae9a05
Compare
edafbdb
to
66dfb71
Compare
66dfb71
to
ec853c8
Compare
426edbd
to
b6c5236
Compare
6014615
to
7fb7601
Compare
@@ -0,0 +1 @@ | |||
*.scss |
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.
I created a separate ticket to use prettier to clean up css files, if we want to: #396
config.responder.error_status = :unprocessable_entity | ||
config.responder.redirect_status = :see_other |
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.
These are recommended changes as part of the Devise upgrade: https://github.com/heartcombo/devise/blob/main/CHANGELOG.md#490---2023-02-17
get 'movies/modal', to: 'movies#modal', as: :movie_modal | ||
post 'movies/modal', to: 'movies#modal', as: :movie_modal |
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.
turbo_streams can't be used with get
requests, so this is why this is changed to a post
.
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.
huh. interesting. i guess i hadn't thought about that, but it makes sense.
sleep 0.25 | ||
fill_in "user_login", with: user.email | ||
find("#user_password") | ||
fill_in "user_password", with: user.password | ||
click_button "log_in_button_new_session" | ||
sleep 0.25 |
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.
Unsure why these sleeps are needed now, but it solved the problem 🤷
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.
it might be that waiting for hotwire thing i am about to mention in a comment below... 😆
max_time = Capybara::Helpers.monotonic_time + Capybara.default_max_wait_time | ||
while Capybara::Helpers.monotonic_time < max_time | ||
finished = finished_all_ajax_requests? | ||
if finished | ||
break | ||
else | ||
sleep 0.1 | ||
end | ||
end | ||
raise 'wait_for_ajax timeout' unless finished |
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.
Was googling on a more updated way of handling this, and found this code, which was basically copied and pasted
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.
On a related note, at work we discovered a hack where we wait for the hotwire to connect before doing the next cypress action. Just throwing that idea out there in case it becomes relevant to our interests
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.
oooh, interesting. i did a quick googling and didn't find anything. but i will def keep that in mind for the frontend redo since all the frontend tests are gonna need to be addressed.
adapter: redis | ||
url: redis://localhost:6379/1 |
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.
auto-added by rails
{ | ||
"engines": { | ||
"node": "20.9.0", | ||
"yarn": "1.22.19" | ||
} | ||
} |
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.
this was due to warnings from heroku as well as fighting with asset pipeline stuff.
TLDR: it specifies a version of these to be used, even though we're not using them.
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.
ewww
@@ -25,16 +25,16 @@ def create | |||
|
|||
def update | |||
@listing = Listing.find_by("list_id = ? AND movie_id = ?", params[:list_id], params[:movie_id]) | |||
# TODO: refactor to be more efficient |
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.
ticket for refactoring: #400
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.
This file is no longer needed with the Rails 7 way of using importmaps
app/assets/javascripts/z.js
Outdated
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 bits of this that we still need were moved to autocomplete.js
(named that way because it only deals with autocmoplete)
<%= turbo_stream.update( | ||
"movie_rated_#{@movie.tmdb_id}", | ||
partial: 'movies/movie_rating', | ||
locals: { movie: @movie } | ||
) | ||
%> | ||
<%= turbo_stream.update( | ||
"movie_show_rated_#{@movie.tmdb_id}", | ||
partial: 'movies/movie_rating', | ||
locals: { movie: @movie } | ||
) | ||
%> |
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.
This is a result of us having complexity around showing things in the modal vs show page, for example
.gitignore
Outdated
@@ -38,3 +38,6 @@ coverage/ | |||
|
|||
# Ignore master key for decrypting credentials and more. | |||
/config/master.key | |||
config/credentials.yml.enc |
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.
This config/credentials.yml.enc
file is not supposed to be in the .gitignore file. If it is, I will not have access to the credentials within. This file works in conjunction with the master.key file (which should be in the gitignore and never committed). Rails uses the master.key to decrypt the credentials file so i can access the values stored within, such as api tokens, etc.
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.
oooooh, got it. i removed it from the gitignore. thanks!
gem 'hotwire-rails' | ||
gem 'importmap-rails' |
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.
🔥
@@ -16,3 +16,20 @@ | |||
width: 250px; | |||
margin-left: 40px; | |||
} | |||
|
|||
// SIGN OUT LINK NEEDS TO BE A BUTTON_TO. STYLES MATCH BOOTSTRAP | |||
.navbar #sign_out_nav_link { |
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.
I see that this style is using an id here instead of a class. Is that just because it is already what is in place? If this is a new style, we should be using a class instead.
I'm also seeing this for other styles, so that ^ comment applies to all of the places we have ids for styles.
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.
yeah, it was already in place. i'll just leave it on this branch because on redoing the frontend, i plan to remove all of these ids that i believe were added for tests.
@@ -13,7 +13,7 @@ def create | |||
|
|||
respond_to do |format| | |||
if listing.save | |||
format.js {} | |||
format.turbo_stream | |||
format.html { redirect_to user_list_path(listing.list.owner, listing.list), notice: 'added to your list.' } | |||
format.json { render :show, status: :created, location: listing } |
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.
Just curious: do we need format.json
? If not we could delete it. But maybe that's a separate cleanup PR.
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.
Good call. no, we do not use it at all. I created a separate issue to clean that up: #402
@@ -16,10 +16,12 @@ def destroy | |||
@tagging = current_user.taggings.find_by("tag_id = ? AND movie_id = ?", params[:tag_id], params[:movie_id]) | |||
respond_to do |format| | |||
if @tagging && @tagging.destroy | |||
format.js {} | |||
format.turbo_stream {} | |||
format.html { redirect_to movie_path(@movie), notice: 'Tag was destroyed.' } |
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.
i'm vaguely remembering something from the pragmatic studio tutorial about how we need to handle notices or errors or something in controllers... like we have to specifically declare (:fan: ✋) something now
not a super helpful comment 😆 my brain is sleepy
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.
hmm, yeah, this is a weird one because it'll always be a turbo_stream response. but general handling of notices/errors can be part of the frontend redo.
max_time = Capybara::Helpers.monotonic_time + Capybara.default_max_wait_time | ||
while Capybara::Helpers.monotonic_time < max_time | ||
finished = finished_all_ajax_requests? | ||
if finished | ||
break | ||
else | ||
sleep 0.1 | ||
end | ||
end | ||
raise 'wait_for_ajax timeout' unless finished |
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.
On a related note, at work we discovered a hack where we wait for the hotwire to connect before doing the next cypress action. Just throwing that idea out there in case it becomes relevant to our interests
sleep 0.25 | ||
fill_in "user_login", with: user.email | ||
find("#user_password") | ||
fill_in "user_password", with: user.password | ||
click_button "log_in_button_new_session" | ||
sleep 0.25 |
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.
it might be that waiting for hotwire thing i am about to mention in a comment below... 😆
@@ -11,17 +11,19 @@ | |||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0" /> | |||
|
|||
<%= stylesheet_link_tag 'application', media: 'all'%> | |||
<%= javascript_include_tag 'application'%> | |||
<%= javascript_include_tag 'application' %> | |||
<%= javascript_import_module_tag "autocomplete" %> |
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.
😅 thanks for sticking with it and making this work!
<!--TODO: use importmap for this--> | ||
<script src="//use.fontawesome.com/16a020f0b8.js"></script> |
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.
i have also experienced a lot of bootstrap drama with rails 7 upgrades and general fontawesome unhappiness. so, yeah i'm down to switch to material.
get 'movies/modal', to: 'movies#modal', as: :movie_modal | ||
post 'movies/modal', to: 'movies#modal', as: :movie_modal |
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.
huh. interesting. i guess i hadn't thought about that, but it makes sense.
{ | ||
"engines": { | ||
"node": "20.9.0", | ||
"yarn": "1.22.19" | ||
} | ||
} |
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.
ewww
Related Issues & PRs
Closes #391
Problems Solved
Screenshots
rails-hotwire-in-production.mov
Things Learned
😅