diff --git a/app/javascript/src/javascripts/posts.js.erb b/app/javascript/src/javascripts/posts.js.erb index 580c11e89..faac75e0c 100644 --- a/app/javascript/src/javascripts/posts.js.erb +++ b/app/javascript/src/javascripts/posts.js.erb @@ -9,7 +9,7 @@ let Post = {}; Post.pending_update_count = 0; Post.SWIPE_THRESHOLD = 60; Post.SWIPE_VELOCITY = 0.6; -Post.MAX_RECOMMENDATIONS = 27; // 3 rows of 9 posts at 1920x1080. +Post.MAX_RECOMMENDATIONS = 45; // 3 rows of 9 posts at 1920x1080. Post.initialize_all = function() { @@ -30,6 +30,7 @@ Post.initialize_all = function() { this.initialize_post_sections(); this.initialize_post_image_resize_links(); this.initialize_post_image_resize_to_window_link(); + this.initialize_recommended(); if (CurrentUser.data("always-resize-images") || (Utility.meta("viewport") && (window.screen.width <= 660))) { $("#image-resize-to-window-link").click(); @@ -582,6 +583,17 @@ Post.initialize_saved_searches = function() { }); } +Post.initialize_recommended = function() { + $(document).on("click.danbooru", ".post-preview .more-recommended-posts", async function (event) { + event.preventDefault(); + + let post_id = $(this).parents(".post-preview").data("id"); + $("#recommended").addClass("loading-recommended-posts"); + await $.get("/recommended_posts.js", { search: { post_id: post_id }, limit: Post.MAX_RECOMMENDATIONS }); + $("#recommended").removeClass("loading-recommended-posts"); + }); +}; + Post.update_tag_count = function(event) { let string = "0 tags"; let count = 0; diff --git a/app/javascript/src/styles/specific/posts.scss b/app/javascript/src/styles/specific/posts.scss index 18f9a520f..f354d926d 100644 --- a/app/javascript/src/styles/specific/posts.scss +++ b/app/javascript/src/styles/specific/posts.scss @@ -366,6 +366,11 @@ div#c-posts { margin-top: 0.5em; } + #recommended.loading-recommended-posts { + pointer-events: none; + opacity: 0.5; + } + #pool-nav, #search-seq-nav, #favgroup-nav { li { position: relative; diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 59d364791..48a3aa11c 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -86,13 +86,19 @@ class PostPresenter < Presenter locals[:size] = nil end + if options[:recommended] + locals[:recommended] = options[:recommended].round(1) + else + locals[:recommended] = nil + end + ApplicationController.render(partial: "posts/partials/index/preview", locals: locals) end - def self.preview_class(post, highlight_score: nil, pool: nil, size: nil, similarity: nil, compact: nil, **options) + def self.preview_class(post, highlight_score: nil, pool: nil, size: nil, similarity: nil, recommended: nil, compact: nil, **options) klass = ["post-preview"] # klass << " large-cropped" if post.has_cropped? && options[:show_cropped] - klass << "captioned" if pool || size || similarity + klass << "captioned" if pool || size || similarity || recommended klass << "post-status-pending" if post.is_pending? klass << "post-status-flagged" if post.is_flagged? klass << "post-status-deleted" if post.is_deleted? diff --git a/app/views/posts/partials/index/_preview.html.erb b/app/views/posts/partials/index/_preview.html.erb index dce16f23a..a9f00ebb1 100644 --- a/app/views/posts/partials/index/_preview.html.erb +++ b/app/views/posts/partials/index/_preview.html.erb @@ -32,4 +32,20 @@ <%= link_to "#{similarity}%", iqdb_queries_path(post_id: post.id) %> similarity
<% end -%> + + <% if recommended -%> +
+ <%= link_to recommended_posts_path(search: { post_id: post.id }), class: "more-recommended-posts", "data-post-id": post.id do %>
+ <%= post.fav_count %>
+
+ <% if post.favorited_by?(CurrentUser.id) %>
+
+ <% else %>
+
+ <% end %>
+
+
more ยป
+ <% end %>
+