diff --git a/app/controllers/cards/pins_controller.rb b/app/controllers/cards/pins_controller.rb index 1f6c1aaa8..235393178 100644 --- a/app/controllers/cards/pins_controller.rb +++ b/app/controllers/cards/pins_controller.rb @@ -6,24 +6,20 @@ class Cards::PinsController < ApplicationController def create pin = @card.pin_by Current.user - - broadcast_my_new pin - redirect_to card_pin_path(@card) + broadcast_add_to_tray pin end def destroy pin = @card.unpin_by Current.user - - broadcast_my_removed pin - redirect_to card_pin_path(@card) + broadcast_remove_from_tray pin end private - def broadcast_my_new(pin) - pin.broadcast_prepend_later_to [ Current.user, :pins ], target: "pins", partial: "my/pins/pin" + def broadcast_add_to_tray(pin) + pin.broadcast_prepend_to [ Current.user, :pins_tray ], target: "pins", partial: "my/pins/pin" end - def broadcast_my_removed(pin) - pin.broadcast_remove_to [ Current.user, :pins ] + def broadcast_remove_from_tray(pin) + pin.broadcast_remove_to [ Current.user, :pins_tray ] end end diff --git a/app/views/cards/pins/_pin_button.html.erb b/app/views/cards/pins/_pin_button.html.erb new file mode 100644 index 000000000..e08308829 --- /dev/null +++ b/app/views/cards/pins/_pin_button.html.erb @@ -0,0 +1,11 @@ +
diff --git a/app/views/cards/pins/create.turbo_stream.erb b/app/views/cards/pins/create.turbo_stream.erb new file mode 100644 index 000000000..b1dd787e9 --- /dev/null +++ b/app/views/cards/pins/create.turbo_stream.erb @@ -0,0 +1 @@ +<%= turbo_stream.replace [ @card, :pin_button ], partial: "cards/pins/pin_button", locals: { card: @card } %> diff --git a/app/views/cards/pins/destroy.turbo_stream.erb b/app/views/cards/pins/destroy.turbo_stream.erb new file mode 100644 index 000000000..d54dea5f1 --- /dev/null +++ b/app/views/cards/pins/destroy.turbo_stream.erb @@ -0,0 +1 @@ +<%= render template: "cards/pins/create" %> diff --git a/app/views/cards/pins/show.html.erb b/app/views/cards/pins/show.html.erb index 64eb1ad5c..c8ac69d7e 100644 --- a/app/views/cards/pins/show.html.erb +++ b/app/views/cards/pins/show.html.erb @@ -1,13 +1,3 @@ <%= turbo_frame_tag dom_id(@card, :pin) do %> - <% if @card.pinned_by? Current.user %> - <%= button_to card_pin_path(@card), method: :delete, class: "btn btn--reversed" do %> - <%= icon_tag "pinned" %> - Un-pin this card - <% end %> - <% else %> - <%= button_to card_pin_path(@card), class: "btn" do %> - <%= icon_tag "unpinned" %> - Pin this card - <% end %> - <% end %> + <%= render "cards/pins/pin_button", card: @card %> <% end %> diff --git a/app/views/my/pins/_tray.html.erb b/app/views/my/pins/_tray.html.erb index 70c1d5a16..ddd39fdfe 100644 --- a/app/views/my/pins/_tray.html.erb +++ b/app/views/my/pins/_tray.html.erb @@ -1,4 +1,4 @@ -<%= turbo_stream_from Current.user, :pins %> +<%= turbo_stream_from Current.user, :pins_tray %> <%= tag.dialog id: "pin-tray", class: "tray pin-tray", data: { controller: "dialog", turbo_permanent: true, dialog_modal_value: false, dialog_target: "dialog", action: "keydown.esc->dialog#close:stop click@document->dialog#closeOnClickOutside" } do %> diff --git a/test/controllers/cards/pins_controller_test.rb b/test/controllers/cards/pins_controller_test.rb index 39b12a053..3bc569827 100644 --- a/test/controllers/cards/pins_controller_test.rb +++ b/test/controllers/cards/pins_controller_test.rb @@ -8,24 +8,24 @@ class Cards::PinsControllerTest < ActionDispatch::IntegrationTest test "create" do assert_changes -> { cards(:layout).pinned_by?(users(:kevin)) }, from: false, to: true do perform_enqueued_jobs do - assert_turbo_stream_broadcasts([ users(:kevin), :pins ], count: 1) do - post card_pin_path(cards(:layout)) + assert_turbo_stream_broadcasts([ users(:kevin), :pins_tray ], count: 1) do + post card_pin_path(cards(:layout)), as: :turbo_stream end end end - assert_redirected_to card_pin_path(cards(:layout)) + assert_response :success end test "destroy" do assert_changes -> { cards(:shipping).pinned_by?(users(:kevin)) }, from: true, to: false do perform_enqueued_jobs do - assert_turbo_stream_broadcasts([ users(:kevin), :pins ], count: 1) do - delete card_pin_path(cards(:shipping)) + assert_turbo_stream_broadcasts([ users(:kevin), :pins_tray ], count: 1) do + delete card_pin_path(cards(:shipping)), as: :turbo_stream end end end - assert_redirected_to card_pin_path(cards(:shipping)) + assert_response :success end end