Create Mute Rules using Turbo Streams
This commit is contained in:
parent
97d55127e4
commit
589b753df3
|
@ -6,4 +6,16 @@ class Settings::MutesController < ApplicationController
|
|||
def index
|
||||
@rules = MuteRule.where(user: current_user)
|
||||
end
|
||||
|
||||
def create
|
||||
rule = MuteRule.create!(user: current_user, muted_phrase: params[:muted_phrase])
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream do
|
||||
render turbo_stream: turbo_stream.append("rules", partial: "settings/mutes/rule", locals: { rule: })
|
||||
end
|
||||
|
||||
format.html { redirect_to settings_muted_path }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
.form-group{ id: "rule_#{rule.id}" }
|
||||
.input-group
|
||||
%input.form-control{ disabled: true, value: rule.muted_phrase }
|
||||
.input-group-append
|
||||
= button_to settings_muted_destroy_path(rule.id), method: :delete, class: "btn btn-danger" do
|
||||
= t("voc.remove")
|
|
@ -3,25 +3,15 @@
|
|||
%h2= t(".heading")
|
||||
%p= t(".body")
|
||||
%p= t(".note")
|
||||
.js-rules-list
|
||||
#rules
|
||||
- @rules.each do |rule|
|
||||
= render "settings/mutes/rule", rule: rule
|
||||
.form-group
|
||||
%form{ action: settings_muted_path, method: "post" }
|
||||
.input-group
|
||||
%input.form-control{ disabled: true, value: rule.muted_phrase }
|
||||
%input.form-control#muted_phrase{ name: :muted_phrase, placeholder: t(".placeholder") }
|
||||
.input-group-append
|
||||
%button.btn.btn-danger{ type: "button", data: { id: rule.id } }= t(".actions.remove")
|
||||
.form-group
|
||||
%form{ data: { turbo: false } }
|
||||
.input-group
|
||||
%input.form-control#new-rule-text{ placeholder: t(".placeholder") }
|
||||
.input-group-append
|
||||
%button.btn.btn-primary#new-rule-submit{ type: "submit" }= t(".actions.add")
|
||||
%template#rule-template
|
||||
.form-group
|
||||
.input-group
|
||||
%input.form-control{ disabled: true }
|
||||
.input-group-append
|
||||
%button.btn.btn-danger{ type: "button" }= t(".actions.remove")
|
||||
%button.btn.btn-primary{ type: "submit" }= t("voc.add")
|
||||
|
||||
- provide(:title, generate_title(t(".title")))
|
||||
- parent_layout "user/settings"
|
||||
|
|
Loading…
Reference in New Issue