Merge pull request #410 from basecamp/pin-without-redirect
Pin without redirect
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<div id="<%= dom_id(card, :pin_button) %>">
|
||||
<% if card.pinned_by? Current.user %>
|
||||
<%= button_to card_pin_path(card), method: :delete, class: "btn btn--reversed" do %>
|
||||
<%= icon_tag "pinned" %> <span class="for-screen-reader">Un-pin this card</span>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= button_to card_pin_path(card), class: "btn" do %>
|
||||
<%= icon_tag "unpinned" %> <span class="for-screen-reader">Pin this card</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -0,0 +1 @@
|
||||
<%= turbo_stream.replace [ @card, :pin_button ], partial: "cards/pins/pin_button", locals: { card: @card } %>
|
||||
@@ -0,0 +1 @@
|
||||
<%= render template: "cards/pins/create" %>
|
||||
@@ -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" %>
|
||||
<span class="for-screen-reader">Un-pin this card</span>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= button_to card_pin_path(@card), class: "btn" do %>
|
||||
<%= icon_tag "unpinned" %>
|
||||
<span class="for-screen-reader">Pin this card</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= render "cards/pins/pin_button", card: @card %>
|
||||
<% end %>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user