From f008dff3f4c5abbcace5979b19739486d18efd6a Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Fri, 19 Jan 2024 01:39:25 -0800 Subject: [PATCH] Remove duplicates from the list of trades Oh yeah, a long-standing limitation. Good thing we're better at stuff now! This is also probably the real cause of the weird number of slight discrepancies between main DTI and DTI 2020 when I eyeballed stuff lol oh, well, that and the missing default-lists. A bit messy! --- app/controllers/items_controller.rb | 14 +++++++++----- app/helpers/items_helper.rb | 10 +++++----- app/views/items/show.html.haml | 8 ++++---- config/locales/en-MEEP.yml | 2 +- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- config/locales/pt.yml | 2 +- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 2ee9d51c..d8e90fd1 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -71,12 +71,16 @@ class ItemsController < ApplicationController @basic_colored_pet_types_by_species_id = PetType.special_color_or_basic(@item.special_color). includes_child_translations.group_by(&:species) - trading_closet_hangers = @item.closet_hangers.trading.newest. - user_is_active.includes(:user) + trading_closet_hangers = @item.closet_hangers.trading.includes(:user). + user_is_active.order('users.last_trade_activity_at DESC') - @trading_closet_hangers_by_owned = { - true => trading_closet_hangers.filter { |c| c.owned? }, - false => trading_closet_hangers.filter { |c| c.wanted? }, + + owned_trading_hangers = trading_closet_hangers.filter { |c| c.owned? } + wanted_trading_hangers = trading_closet_hangers.filter { |c| c.wanted? } + + @trading_users_by_owned = { + true => owned_trading_hangers.map(&:user).uniq, + false => wanted_trading_hangers.map(&:user).uniq, } if user_signed_in? diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb index 3a4bb483..6f37343a 100644 --- a/app/helpers/items_helper.rb +++ b/app/helpers/items_helper.rb @@ -83,14 +83,14 @@ module ItemsHelper "https://www.neopets.com/genie.phtml?type=process_genie&criteria=exact&auctiongenie=#{CGI::escape item.name}" end - def trading_closet_hangers_header(owned, count) + def trading_users_header(owned, count) ownership_key = owned ? 'owned' : 'wanted' - translate ".trading_closet_hangers.header.#{ownership_key}", :count => count + translate ".trading_users.header.#{ownership_key}", :count => count end - def render_trading_closet_hangers(owned) - @trading_closet_hangers_by_owned[owned].map do |hanger| - link_to hanger.user.name, user_closet_hangers_path(hanger.user) + def render_trading_users(owned) + @trading_users_by_owned[owned].map do |user| + link_to user.name, user_closet_hangers_path(user) end.to_sentence.html_safe end diff --git a/app/views/items/show.html.haml b/app/views/items/show.html.haml index 2b5f59a4..c03c742b 100644 --- a/app/views/items/show.html.haml +++ b/app/views/items/show.html.haml @@ -43,11 +43,11 @@ - [true, false].each do |owned| %p %strong - = trading_closet_hangers_header(owned, @trading_closet_hangers_by_owned[owned].size) - = render_trading_closet_hangers(owned) + = trading_users_header(owned, @trading_users_by_owned[owned].size) + = render_trading_users(owned) %span.toggle - %span.more= t '.trading_closet_hangers.show_more' - %span.less= t '.trading_closet_hangers.show_less' + %span.more= t '.trading_users.show_more' + %span.less= t '.trading_users.show_less' - if user_signed_in? #your-items-form diff --git a/config/locales/en-MEEP.yml b/config/locales/en-MEEP.yml index e5c0e3b2..a40f5abd 100644 --- a/config/locales/en-MEEP.yml +++ b/config/locales/en-MEEP.yml @@ -285,7 +285,7 @@ en-MEEP: occupied_header: Occupeeps restricted_header: Restreeps none: Meepless - trading_closet_hangers: + trading_users: header: owned: zero: We don't know anymeep who has this item meep for trade. diff --git a/config/locales/en.yml b/config/locales/en.yml index ae394ee9..62591b51 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -314,7 +314,7 @@ en: occupied_header: Occupies restricted_header: Restricts none: None - trading_closet_hangers: + trading_users: header: owned: zero: We don't know anyone who has this item up for trade. diff --git a/config/locales/es.yml b/config/locales/es.yml index bcbd7e3e..0c0c643c 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -224,7 +224,7 @@ es: occupied_header: Ocupa restricted_header: Restringe none: Nada - trading_closet_hangers: + trading_users: header: owned: zero: No conocemos a nadie que tenga este objeto para intercambiar. diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 1b1cc1dc..8f5dc994 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -224,7 +224,7 @@ pt: occupied_header: Ocupações restricted_header: Restrições none: Nada - trading_closet_hangers: + trading_users: header: owned: zero: Ninguém quer trocar esse item