[openstreetmap/openstreetmap-website] Add Turbo to replace custom JS (PR #4562)
Tom Hughes
notifications at github.com
Wed Mar 20 16:11:13 UTC 2024
@tomhughes commented on this pull request.
> @@ -108,6 +112,7 @@ $(document).ready(function () {
updateHeader();
$(window).resize(updateHeader);
+ document.addEventListener("turbo:render", updateHeader);
So obviously this comes down to the whether-to-use-jquery question which was briefly mentioned before, but obviously this is using a raw API for something that we have generally done with jquery in the past.
> });
- $(".inbox-mark-read").on("ajax:success", function (event, data) {
- updateHtml(data);
- updateReadState(this, true);
+ $(".messages-table .message-summary").on("turbo:before-morph-element", function (event) {
+ if (event.target.querySelector("[data-is-destroyed]")) {
Again this is a raw API where confusingly two lines later it uses jquery instead...
> @@ -2,6 +2,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<%= javascript_include_tag "es6" unless browser.es6? %>
+ <%= javascript_include_tag "turbo", :type => "module" %>
What was the thinking behind making this a separate include rather than adding it to the application bundle? or is it necessary in order to include it as a module? I confess to not understanding javascript modules and how they interact with other sorts of javascript and rails assets very well...
> <td><%= link_to message_summary.sender.display_name, user_path(message_summary.sender) %></td>
<td><%= link_to message_summary.title, message_path(message_summary) %></td>
<td class="text-nowrap"><%= l message_summary.sent_on, :format => :friendly %></td>
<td class="text-nowrap d-flex justify-content-end gap-1">
- <%= button_to t(".unread_button"), message_mark_path(message_summary, :mark => "unread"), :remote => true, :class => "btn btn-sm btn-primary", :form => { :class => "inbox-mark-unread", :hidden => !message_summary.message_read? } %>
- <%= button_to t(".read_button"), message_mark_path(message_summary, :mark => "read"), :remote => true, :class => "btn btn-sm btn-primary", :form => { :class => "inbox-mark-read", :hidden => message_summary.message_read? } %>
- <%= button_to t(".destroy_button"), message_path(message_summary, :referer => request.fullpath), :method => :delete, :remote => true, :class => "btn btn-sm btn-danger", :form_class => "inbox-destroy" %>
+ <%= button_to t(".unread_button"), message_mark_path(message_summary, :mark => "unread"), :class => "btn btn-sm btn-primary", :form => { :"data-turbo" => true, :class => "inbox-mark-unread", :hidden => !message_summary.message_read? } %>
I'm not a fan of `:"..."` symbols I have to say... Can this be done as `:data => { :turbo => true }` which I think is how we've normally done data, or does that not work in this context?
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4562#pullrequestreview-1949364479
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/4562/review/1949364479 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240320/35f4666d/attachment-0001.htm>
More information about the rails-dev
mailing list