Add `RelationshipsController`
This commit is contained in:
parent
0877b938a3
commit
be947bf4e2
|
@ -0,0 +1,47 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RelationshipsController < ApplicationController
|
||||
include TurboStreamable
|
||||
|
||||
before_action :authenticate_user!
|
||||
|
||||
turbo_stream_actions :create, :destroy
|
||||
|
||||
def create
|
||||
UseCase::Relationship::Create.call(
|
||||
source_user: current_user,
|
||||
target_user: ::User.find_by!(screen_name: params[:screen_name]),
|
||||
type: params[:type]
|
||||
)
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream do
|
||||
render turbo_stream: [
|
||||
turbo_stream.replace("#{params[:type]}-#{params[:screen_name]}", partial: "relationships/destroy", locals: { type: params[:type], screen_name: params[:screen_name] }),
|
||||
render_toast(t(".#{params[:type]}.success"))
|
||||
]
|
||||
end
|
||||
|
||||
format.html { redirect_back(fallback_location: user_path(username: params[:screen_name])) }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
UseCase::Relationship::Destroy.call(
|
||||
source_user: current_user,
|
||||
target_user: ::User.find_by!(screen_name: params[:screen_name]),
|
||||
type: params[:type]
|
||||
)
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream do
|
||||
render turbo_stream: [
|
||||
turbo_stream.replace("#{params[:type]}-#{params[:screen_name]}", partial: "relationships/create", locals: { type: params[:type], screen_name: params[:screen_name] }),
|
||||
render_toast(t(".#{params[:type]}.success"))
|
||||
]
|
||||
end
|
||||
|
||||
format.html { redirect_back(fallback_location: user_path(username: params[:screen_name])) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
- if type == "follow"
|
||||
= button_to relationships_path(screen_name:, type:), form: { id: "#{type}-#{screen_name}" }, class: "btn btn-primary", form_class: "d-grid" do
|
||||
= t("voc.follow")
|
||||
|
||||
- if type == "block"
|
||||
= button_to relationships_path(screen_name:, type:), form: { id: "#{type}-#{screen_name}" }, class: "dropdown-item" do
|
||||
%i.fa.fa-minus-circle.fa-fw
|
||||
= t("voc.block")
|
||||
|
||||
- if type == "mute"
|
||||
= button_to relationships_path(screen_name:, type:), form: { id: "#{type}-#{screen_name}" }, class: "dropdown-item" do
|
||||
%i.fa.fa-volume-off.fa-fw
|
||||
= t("voc.mute")
|
|
@ -0,0 +1,13 @@
|
|||
- if type == "follow"
|
||||
= button_to relationships_path(screen_name:, type:), method: :delete, form: { id: "#{type}-#{screen_name}" }, class: "btn btn-primary", form_class: "d-grid" do
|
||||
= t("voc.unfollow")
|
||||
|
||||
- if type == "block"
|
||||
= button_to relationships_path(screen_name:, type:), method: :delete, form: { id: "#{type}-#{screen_name}" }, class: "dropdown-item" do
|
||||
%i.fa.fa-minus-circle.fa-fw
|
||||
= t("voc.unblock")
|
||||
|
||||
- if type == "mute"
|
||||
= button_to relationships_path(screen_name:, type:), method: :delete, form: { id: "#{type}-#{screen_name}" }, class: "dropdown-item" do
|
||||
%i.fa.fa-volume-off.fa-fw
|
||||
= t("voc.unmute")
|
|
@ -147,6 +147,7 @@ Rails.application.routes.draw do
|
|||
get "/inbox", to: "inbox#show", as: :inbox
|
||||
|
||||
resource :subscriptions, controller: :subscriptions, only: %i[create destroy]
|
||||
resource :relationships, only: %i[create destroy]
|
||||
|
||||
get "/user/:username", to: "user#show"
|
||||
get "/@:username", to: "user#show", as: :user
|
||||
|
|
Loading…
Reference in New Issue