diff --git a/app/controllers/settings/mutes_controller.rb b/app/controllers/settings/mutes_controller.rb index 20810123..6740a1ac 100644 --- a/app/controllers/settings/mutes_controller.rb +++ b/app/controllers/settings/mutes_controller.rb @@ -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 diff --git a/app/views/settings/mutes/_rule.html.haml b/app/views/settings/mutes/_rule.html.haml new file mode 100644 index 00000000..50e6c300 --- /dev/null +++ b/app/views/settings/mutes/_rule.html.haml @@ -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") diff --git a/app/views/settings/mutes/index.html.haml b/app/views/settings/mutes/index.html.haml index ecc092e4..1ecfd9c1 100644 --- a/app/views/settings/mutes/index.html.haml +++ b/app/views/settings/mutes/index.html.haml @@ -3,25 +3,15 @@ %h2= t(".heading") %p= t(".body") %p= t(".note") - .js-rules-list + #rules - @rules.each do |rule| - .form-group - .input-group - %input.form-control{ disabled: true, value: rule.muted_phrase } - .input-group-append - %button.btn.btn-danger{ type: "button", data: { id: rule.id } }= t(".actions.remove") + = render "settings/mutes/rule", rule: rule .form-group - %form{ data: { turbo: false } } - .input-group - %input.form-control#new-rule-text{ placeholder: t(".placeholder") } + %form{ action: settings_muted_path, method: "post" } + .input-group + %input.form-control#muted_phrase{ name: :muted_phrase, 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"