-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1421 from Retrospring/feature/turbo-relationships
Move relationship functionality to Turbo Streams
- Loading branch information
Showing
11 changed files
with
124 additions
and
202 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
class RelationshipsController < ApplicationController | ||
include TurboStreamable | ||
|
||
before_action :authenticate_user! | ||
|
||
turbo_stream_actions :create, :destroy | ||
|
||
def create | ||
params.require :screen_name | ||
|
||
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
import { userActionHandler } from './action'; | ||
import { userReportHandler } from './report'; | ||
import registerEvents from 'retrospring/utilities/registerEvents'; | ||
|
||
export default (): void => { | ||
registerEvents([ | ||
{ type: 'click', target: 'button[name=user-action]', handler: userActionHandler, global: true }, | ||
{ type: 'click', target: '[data-action=block], [data-action=unblock]', handler: userActionHandler, global: true }, | ||
{ type: 'click', target: '[data-action=mute], [data-action=unmute]', handler: userActionHandler, global: true }, | ||
{ type: 'click', target: 'a[data-action=report-user]', handler: userReportHandler, global: true } | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
- 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.