Show toasts on pin/unpin

This commit is contained in:
Karina Kwiatek 2023-02-12 20:29:36 +01:00
parent dcad9073a8
commit 520f7eb9ef
2 changed files with 21 additions and 2 deletions

View File

@ -3,6 +3,10 @@
class AnswerController < ApplicationController
before_action :authenticate_user!, only: %i[pin unpin]
include TurboStreamable
turbo_stream_actions :pin, :unpin
def show
@answer = Answer.includes(comments: %i[user smiles], question: [:user], smiles: [:user]).find(params[:id])
@display_all = true
@ -25,7 +29,12 @@ class AnswerController < ApplicationController
respond_to do |format|
format.html { redirect_to(user_path(username: current_user.screen_name)) }
format.turbo_stream { render "pin", locals: { answer: } }
format.turbo_stream do
render turbo_stream: [
turbo_stream.update("ab-pin-#{answer.id}", partial: "actions/pin", locals: { answer: }),
render_toast(t(".success"))
]
end
end
end
@ -35,7 +44,12 @@ class AnswerController < ApplicationController
respond_to do |format|
format.html { redirect_to(user_path(username: current_user.screen_name)) }
format.turbo_stream { render "pin", locals: { answer: } }
format.turbo_stream do
render turbo_stream: [
turbo_stream.update("ab-pin-#{answer.id}", partial: "actions/pin", locals: { answer: }),
render_toast(t(".success"))
]
end
end
end
end

View File

@ -212,3 +212,8 @@ en:
timeline:
public:
title: "Public Timeline"
answer:
pin:
success: "This answer will now appear at the top of your profile."
unpin:
success: "This answer will no longer be pinned to the top of your profile."