docbrown/app/controllers/followings_controller.rb
Ridhwana 5266dd1afb
Showing and hiding tags in the Following and Hidden Tags Pages (#19954)
* feat: remove updated weights

* feat: click on following on the following tags page

* feat: add and listen for the following button click

* fix: dropdowns

* feat: handle hide button click

* feat: update the nav link for following tags

* feat: handel the 'unhide button' on the hidden tags page

* feat: add the styling for the buttons

* feat: add localization

* feat: remove the brand from the card

* feat: add some styling to the page

* feat: init scrolling

* chore: update the name of the file

* feat: abstract out the comment fetch code

* fix: close the attribute

* feta: make some adjustments to where the tag adn the follow show up

* rename class from plural to singular

* feat: updae the comment

* feat: add a mutation observer to initialize the dropdown

* test: follow_craete

* chore: remove irrelevant test

* feat: update the cypress seeds

* feat: update the cypress seeds

* spec: write soem initial tests for the following tags page

* spec: update the unfollow cypress spec

* spec: update the hide cypress spec

* spec: update the posts published spec

* note to add test for pagination

* spec: hidden tags page

* feat: remove aria pressed attributes

* fix: ordering by explicit points gets the page params confused and returns the incorrect and not all results on pagination

* fix: use explicit points

* feat: remove the message at the top of the following and hidden tags page

* chore: remove comment and rather add it to the PR itself

* refactor: do all the actions on success

* feat: refactor the dashboard tag file

* refactor: only show the tagId and followId dataset attributes on the dashboard__tag__container

* feat: disconnect the observer

* chore: add some documentation

* feat: add fr localization

* chore: empty line

* fix: update the dashboardTags page to first declare the observer"
"
"

* fix: update the rails test

* Empty commit

* fix: because I added more tags, the dropdown was longre and covering the body of the editor hence it could not find the text, so I've escaped after selecting my tags
2023-08-25 14:49:39 +02:00

54 lines
1.8 KiB
Ruby

class FollowingsController < ApplicationController
before_action :authenticate_user!
before_action -> { limit_per_page(default: 80, max: 1000) }
ATTRIBUTES_FOR_SERIALIZATION = %i[id followable_id followable_type].freeze
TAGS_ATTRIBUTES_FOR_SERIALIZATION = [*ATTRIBUTES_FOR_SERIALIZATION, :points, :explicit_points].freeze
def users
relation = current_user.follows_by_type("User")
.select(ATTRIBUTES_FOR_SERIALIZATION)
.order(created_at: :desc)
@follows = load_follows_and_paginate(relation)
end
def tags
relation = current_user.follows_by_type("ActsAsTaggableOn::Tag").select(TAGS_ATTRIBUTES_FOR_SERIALIZATION)
relation = if params[:controller_action] == "hidden_tags"
relation.where(explicit_points: (...0))
else
relation.where(explicit_points: (0...))
end
relation = relation.order(created_at: :desc)
@followed_tags = load_follows_and_paginate(relation)
end
def organizations
relation = current_user.follows_by_type("Organization")
.select(ATTRIBUTES_FOR_SERIALIZATION)
.order(created_at: :desc)
@followed_organizations = load_follows_and_paginate(relation)
end
def podcasts
relation = current_user.follows_by_type("Podcast")
.select(ATTRIBUTES_FOR_SERIALIZATION)
.order(created_at: :desc)
@followed_podcasts = load_follows_and_paginate(relation)
end
private_constant :ATTRIBUTES_FOR_SERIALIZATION
private_constant :TAGS_ATTRIBUTES_FOR_SERIALIZATION
private
def limit_per_page(default:, max:)
per_page = (params[:per_page] || default).to_i
@follows_limit = [per_page, max].min
end
def load_follows_and_paginate(relation)
relation.includes(:followable).page(params[:page]).per(@follows_limit)
end
end