From 520f7eb9ef7501b906a1175b252a46da8f8213f6 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 12 Feb 2023 20:29:36 +0100 Subject: [PATCH] Show toasts on pin/unpin --- app/controllers/answer_controller.rb | 18 ++++++++++++++++-- config/locales/controllers.en.yml | 5 +++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/controllers/answer_controller.rb b/app/controllers/answer_controller.rb index 6b045f7a..d5e70881 100644 --- a/app/controllers/answer_controller.rb +++ b/app/controllers/answer_controller.rb @@ -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 diff --git a/config/locales/controllers.en.yml b/config/locales/controllers.en.yml index ebd15114..ff41c0c6 100644 --- a/config/locales/controllers.en.yml +++ b/config/locales/controllers.en.yml @@ -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."