Retrospring/app/controllers/settings/mutes_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class Settings::MutesController < ApplicationController
include TurboStreamable
before_action :authenticate_user!
turbo_stream_actions :create, :destroy
def index
2022-12-28 19:38:36 -08:00
@users = current_user.muted_users
@rules = MuteRule.where(user: current_user)
end
2022-11-18 12:47:37 -08:00
def create
result = UseCase::MuteRule::Create.call(user: current_user, phrase: params[:muted_phrase])
2022-11-18 12:47:37 -08:00
respond_to do |format|
format.turbo_stream do
render turbo_stream: [
turbo_stream.replace("form", partial: "settings/mutes/form"),
turbo_stream.append("rules", partial: "settings/mutes/rule", locals: { rule: result[:resource] }),
render_toast(t(".success"))
]
2022-11-18 12:47:37 -08:00
end
format.html { redirect_to settings_muted_path }
end
end
2022-11-18 12:48:12 -08:00
def destroy
rule = MuteRule.find(params[:id])
2022-11-18 13:51:05 -08:00
authorize rule
UseCase::MuteRule::Destroy.call(rule:)
2022-11-18 12:48:12 -08:00
respond_to do |format|
format.turbo_stream do
render turbo_stream: [
turbo_stream.remove("rule_#{params[:id]}"),
render_toast(t(".success"))
]
2022-11-18 12:48:12 -08:00
end
format.html { redirect_to settings_muted_path }
end
end
end