/favorites: replace favorites view with ordfav: search.

Make /favorites redirect to a ordfav:<user> search instead of having a
separate view just for favorites. This duplicated a lot of code for no
good reason.
This commit is contained in:
evazion
2019-08-31 19:58:38 -05:00
parent 7f7730d249
commit b77eebf136
8 changed files with 19 additions and 249 deletions

View File

@@ -5,22 +5,13 @@ class FavoritesController < ApplicationController
rescue_with Favorite::Error, status: 422
def index
if params[:tags]
redirect_to(posts_path(:tags => params[:tags]))
if params[:user_id].present?
user = User.find(params[:user_id])
redirect_to posts_path(tags: "ordfav:#{user.name}")
elsif CurrentUser.is_member?
redirect_to posts_path(tags: "ordfav:#{CurrentUser.name}")
else
user_id = params[:user_id] || CurrentUser.user.id
@user = User.find(user_id)
if @user.hide_favorites?
raise User::PrivilegeError.new
end
@favorite_set = PostSets::Favorite.new(user_id, params[:page], params)
respond_with(@favorite_set.posts) do |format|
format.xml do
render :xml => @favorite_set.posts.to_xml(:root => "posts")
end
end
redirect_to posts_path
end
end

View File

@@ -1,35 +0,0 @@
module PostSets
class Favorite < PostSets::Base
attr_reader :user, :page, :favorites, :params
def initialize(user_id, page = 1, params = {})
@params = params
@user = ::User.find(user_id)
@favorites = ::Favorite.for_user(user.id).paginate(page, :limit => limit).order("favorites.id desc")
end
def limit
params[:limit] || CurrentUser.user.per_page
end
def tag_array
@tag_array ||= ["fav:#{user.name}"]
end
def tag_string
tag_array.uniq.join(" ")
end
def humanized_tag_string
"fav:#{user.pretty_name}"
end
def posts
@posts ||= favorites.includes(:post).map(&:post).compact
end
def presenter
@presenter ||= ::PostSetPresenters::Favorite.new(self)
end
end
end

View File

@@ -1,12 +0,0 @@
module PostSetPresenters
class Favorite < Base
attr_accessor :post_set, :tag_set_presenter
delegate :favorites, :posts, :to => :post_set
delegate :tag_list_html, to: :tag_set_presenter
def initialize(post_set)
@post_set = post_set
@tag_set_presenter = TagSetPresenter.new(RelatedTagCalculator.frequent_tags_for_posts(post_set.posts).take(25))
end
end
end

View File

@@ -1,43 +0,0 @@
<div id="c-favorites">
<div id="a-index">
<aside id="sidebar">
<%= render "posts/partials/common/search", :path => favorites_path, :tags => @favorite_set.tag_string, :tags_dom_id => "tags" %>
<%= render "posts/partials/index/mode_menu" %>
<%= render "posts/partials/index/blacklist" %>
<section id="tag-box">
<h1>Tags</h1>
<%= @favorite_set.presenter.tag_list_html %>
</section>
<section id="related-box">
<h1>Related</h1>
<ul id="related-list">
<li><%= link_to "Deleted posts", posts_path(:tags => "#{@favorite_set.tag_string} status:deleted"), :rel => "nofollow" %></li>
<li><%= link_to "Random post", random_posts_path(:tags => @favorite_set.tag_string), :id => "random-post", :rel => "nofollow", :"data-shortcut" => "r" %></li>
</ul>
</section>
</aside>
<section id="content">
<h1>Favorites</h1>
<%= render "posts/partials/index/edit" %>
<div id="posts">
<%= @favorite_set.presenter.post_previews_html(self) %>
<%= sequential_paginator(@favorite_set.favorites) %>
</div>
</section>
</div>
</div>
<%= render "posts/partials/common/secondary_links" %>
<% content_for(:page_title) do %>
Favorites - <%= @user.pretty_name %> - <%= Danbooru.config.app_name %>
<% end %>

View File

@@ -7,7 +7,7 @@
<%= subnav_link_to "Recommended", recommended_posts_path(context: "user") %>
<% end %>
<% unless CurrentUser.is_anonymous? %>
<%= subnav_link_to "Favorites", favorites_path %>
<%= subnav_link_to "Favorites", posts_path(tags: "ordfav:#{CurrentUser.user.name}") %>
<%= subnav_link_to "Fav groups", favorite_groups_path %>
<% if CurrentUser.has_saved_searches? %>
<%= subnav_link_to "Saved searches", posts_path(:tags => "search:all") %>

View File

@@ -14,7 +14,7 @@
<% if presenter.has_favorites? %>
<div class="box user-favorites">
<h2>
<%= link_to "Favorites", favorites_path(:user_id => user.id) %>
<%= link_to "Favorites", posts_path(tags: "ordfav:#{user.name}") %>
</h2>
<div>
<% presenter.favorites.each do |post| %>
@@ -39,4 +39,4 @@
</div>
</div>
<% end %>
<% end %>
<% end %>