Create frontend endpoint for pinning answers
This commit is contained in:
parent
5b1340b793
commit
b196909b79
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AnswerController < ApplicationController
|
||||
before_action :authenticate_user!, only: :pin
|
||||
|
||||
def show
|
||||
@answer = Answer.includes(comments: %i[user smiles], question: [:user], smiles: [:user]).find(params[:id])
|
||||
@display_all = true
|
||||
|
@ -16,4 +18,14 @@ class AnswerController < ApplicationController
|
|||
notif.update_all(new: false) unless notif.empty?
|
||||
end
|
||||
end
|
||||
|
||||
def pin
|
||||
answer = Answer.includes(:user).find(params[:id])
|
||||
UseCase::Answer::Pin.call(user: current_user, answer:)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(user_path(username: current_user.screen_name)) }
|
||||
format.turbo_stream { render "pin", locals: { answer: } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,14 +17,7 @@
|
|||
%i.fa.fa-fw.fa-exclamation-triangle
|
||||
= t("voc.report")
|
||||
- else
|
||||
- if answer.pinned?
|
||||
%a.dropdown-item{ href: "#", data: { a_id: answer.id, action: "ab-unpin" } }
|
||||
%i.fa.fa-fw.fa-thumbtack
|
||||
= t(".unpin")
|
||||
- else
|
||||
%a.dropdown-item{ href: "#", data: { a_id: answer.id, action: "ab-pin" } }
|
||||
%i.fa.fa-fw.fa-thumbtack
|
||||
= t(".pin")
|
||||
= render "actions/pin", answer:
|
||||
- if current_user.admin?
|
||||
%a.dropdown-item{ href: rails_admin_path_for_resource(answer), target: "_blank" }
|
||||
%i.fa.fa-fw.fa-gears
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
- if answer.pinned?
|
||||
= button_to pin_answer_path(id: answer.id),
|
||||
class: "dropdown-item",
|
||||
method: :delete,
|
||||
form: { id: "ab-pin-#{answer.id}", data: { turbo_stream: true } } do
|
||||
%i.fa.fa-fw.fa-thumbtack
|
||||
= t(".unpin")
|
||||
- else
|
||||
= button_to pin_answer_path(id: answer.id),
|
||||
class: "dropdown-item",
|
||||
method: :post,
|
||||
form: { id: "ab-pin-#{answer.id}", data: { turbo_stream: true } } do
|
||||
%i.fa.fa-fw.fa-thumbtack
|
||||
= t(".pin")
|
|
@ -0,0 +1,2 @@
|
|||
= turbo_stream.update("ab-pin-#{answer.id}") do
|
||||
= render "actions/pin", answer:
|
|
@ -73,10 +73,11 @@ en:
|
|||
actions:
|
||||
answer:
|
||||
return: "Return to Inbox"
|
||||
pin: "Pin to Profile"
|
||||
unpin: "Unpin from Profile"
|
||||
comment:
|
||||
view_smiles: "View comment smiles"
|
||||
pin:
|
||||
pin: "Pin to Profile"
|
||||
unpin: "Unpin from Profile"
|
||||
share:
|
||||
twitter: "Share on Twitter"
|
||||
tumblr: "Share on Tumblr"
|
||||
|
|
|
@ -146,6 +146,7 @@ Rails.application.routes.draw do
|
|||
get "/user/:username", to: "user#show"
|
||||
get "/@:username", to: "user#show", as: :user
|
||||
get "/@:username/a/:id", to: "answer#show", as: :answer
|
||||
post "/@:username/a/:id/pin", to: "answer#pin", as: :pin_answer
|
||||
get "/@:username/q/:id", to: "question#show", as: :question
|
||||
get "/@:username/followers", to: "user#followers", as: :show_user_followers
|
||||
get "/@:username/followings", to: "user#followings", as: :show_user_followings
|
||||
|
|
Loading…
Reference in New Issue