Skip to content

Commit

Permalink
add preferences ui
Browse files Browse the repository at this point in the history
  • Loading branch information
madhums committed Sep 1, 2023
1 parent b384a85 commit 3eb9af2
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/controllers/preferences_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Preferences controller
#
class PreferencesController < ApplicationController
before_action :authenticate_user!
before_action :set_preference, only: %i[index update]

def index
end

def update
respond_to do |format|
if @preference.update(**permitted_params)
format.html { redirect_to preferences_url, notice: I18n.t("preferences.updated") }
format.json { render :index, status: :ok, location: @preference }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @preference.errors, status: :unprocessable_entity }
end
end
end

private

def set_preference
@preference = current_user.preference
end

def permitted_params
params.require(:preference).permit(
:notify_any_post_in_discussion,
:notify_new_discussion_on_story,
:notify_new_post_on_discussion,
:notify_new_story
)
end
end
31 changes: 31 additions & 0 deletions app/views/preferences/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<% content_for(:title, t('.preferences')) %>

<h2><%= yield(:title) %></h2>

<%= form_for(@preference) do |f| %>
<%= render "users/shared/error_messages", resource: @preference %>

<div class="mb-3 form-check">
<%= f.check_box :notify_new_discussion_on_story, :class => "form-check-input" %>
<%= f.label :notify_new_discussion_on_story, t('.notify_new_discussion_on_story'), :class => "form-check-label" %>
</div>

<div class="mb-3 form-check">
<%= f.check_box :notify_new_post_on_discussion, :class => "form-check-input" %>
<%= f.label :notify_new_post_on_discussion, t('.notify_new_post_on_discussion'), :class => "form-check-label" %>
</div>

<div class="mb-3 form-check">
<%= f.check_box :notify_any_post_in_discussion, :class => "form-check-input" %>
<%= f.label :notify_any_post_in_discussion, t('.notify_any_post_in_discussion'), :class => "form-check-label" %>
</div>

<div class="mb-3 form-check">
<%= f.check_box :notify_new_story, :class => "form-check-input" %>
<%= f.label :notify_new_story, t('.notify_new_story'), :class => "form-check-label" %>
</div>

<div class="actions">
<%= f.submit t('.save'), :class => "btn btn-primary", data: { turbo: false } %>
</div>
<% end %>
9 changes: 9 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ en:
cancel_account_notice: "This is an irreversible action, there is no going back!"
profile: "Profile"
invite: "Invite"
preferences:
updated: "Preferences updated"
index:
preferences: "Preferences"
save: "Save"
notify_new_discussion_on_story: "Notify me of any new discussions on a story I created"
notify_new_post_on_discussion: "Notify me of any new posts on a discussion I created"
notify_any_post_in_discussion: "Notify me of any new posts in a discussion I participate in"
notify_new_story: "Notify me of any new stories that are added"
stories:
created: "Story was successfully created"
updated: "Story was successfully updated"
Expand Down
9 changes: 9 additions & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ nl:
cancel_account_notice: "Dit is een onomkeerbare actie, er is geen weg terug!"
profile: "Profiel"
invite: "Uitnodigen"
preferences:
updated: "Voorkeuren bijgewerkt"
index:
preferences: "Voorkeuren"
save: "Opslaan"
notify_new_discussion_on_story: "Notify me of any new discussions on a story I created"
notify_new_post_on_discussion: "Notify me of any new posts on a discussion I created"
notify_any_post_in_discussion: "Notify me of any new posts in a discussion I participate in"
notify_new_story: "Notify me of any new stories that are added"
stories:
created: "Story was successfully created"
updated: "Story was successfully updated"
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
end
get "stories/:story_id/discussions/:id", to: "discussions#show", as: :story_discussion

resources :preferences, only: %i[index update]

root "home#index"
end

Expand Down

0 comments on commit 3eb9af2

Please sign in to comment.