Sort trades in vaguely-recent order

This logic is copied from DTI 2020! Though I didn't include the part
where we highlight trade matches yet!
This commit is contained in:
Emi Matchu 2024-01-21 03:59:06 -08:00
parent bfb11e94e3
commit 4b9e11fc2a
3 changed files with 28 additions and 5 deletions

View file

@ -1,2 +1,26 @@
module ItemTradesHelper module ItemTradesHelper
def vague_trade_timestamp(last_trade_activity_at)
if last_trade_activity_at >= 1.week.ago
translate "item_trades.index.table.last_active.this_week"
else
last_trade_activity_at.strftime("%b %Y")
end
end
def sorted_vaguely_by_trade_activity(trades)
# First, sort the list in ascending order.
trades_ascending = trades.sort_by do |trade|
if trade.user.last_trade_activity_at >= 1.week.ago
# Sort recent trades in a random order, but still collectively as the
# most recent. (This discourages spamming updates to game the system!)
[1, rand]
else
# Sort older trades by last trade activity.
[0, trade.user.last_trade_activity_at]
end
end
# Then, reverse it!
trades_ascending.reverse!
end
end end

View file

@ -13,13 +13,10 @@
%th= t(".table.headings.user.#{@type}") %th= t(".table.headings.user.#{@type}")
%th= t(".table.headings.lists") %th= t(".table.headings.lists")
%tbody %tbody
- @trades.each do |trade| - sorted_vaguely_by_trade_activity(@trades).each do |trade|
%tr %tr
%td %td
-# TODO: Replace this with the coarse-grained version from 2020, = vague_trade_timestamp trade.user.last_trade_activity_at
-# and translate it!
= time_ago_in_words trade.user.last_trade_activity_at
ago
%td= trade.user.name %td= trade.user.name
%td %td
- if trade.lists.present? - if trade.lists.present?

View file

@ -381,6 +381,8 @@ en:
offering: Owner offering: Owner
seeking: Seeker seeking: Seeker
lists: Lists lists: Lists
last_active:
this_week: This week
not_in_a_list: Not in a list not_in_a_list: Not in a list
no_trades_yet: no_trades_yet:
No trades yet! To add your name to this page, add this item to one of No trades yet! To add your name to this page, add this item to one of