mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 03:15:31 -04:00
Bring back original behavior for recently added
(#37 https://github.com/hkalexling/Mango/issues/37#issuecomment-644748066)
This commit is contained in:
parent
0e4d67cf29
commit
0768e2177b
@ -561,34 +561,38 @@ class Library
|
|||||||
}[0..11]
|
}[0..11]
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_recently_added_entries(username)
|
alias RA = NamedTuple(
|
||||||
# Group all recently added entries into a Array(Array(Title)). Entries
|
entry: Entry,
|
||||||
# from the same title are grouped together
|
percentage: Float64,
|
||||||
grouped_entries = deep_titles
|
grouped_count: Int32)
|
||||||
.map { |t|
|
|
||||||
t.entries.select { |e| e.date_added > 1.months.ago }
|
|
||||||
}
|
|
||||||
.select { |ary| !ary.empty? }
|
|
||||||
# Sort the array by the added date of the last added entry
|
|
||||||
.sort { |a, b|
|
|
||||||
date_added_a = a.map { |e| e.date_added }.max
|
|
||||||
date_added_b = b.map { |e| e.date_added }.max
|
|
||||||
date_added_b <=> date_added_a
|
|
||||||
}[0..11]
|
|
||||||
|
|
||||||
grouped_entries.map do |ary|
|
def get_recently_added_entries(username)
|
||||||
# Get the most recently added entry in the group
|
recently_added = [] of RA
|
||||||
entry = ary.max_by { |e| e.date_added }
|
|
||||||
if ary.size > 1
|
titles.map { |t| t.deep_entries }
|
||||||
percentage = entry.book.load_percentage username
|
.flatten
|
||||||
else
|
.select { |e| e.date_added > 1.month.ago }
|
||||||
percentage = entry.load_percentage username
|
.sort { |a, b| b.date_added <=> a.date_added }
|
||||||
|
.each do |e|
|
||||||
|
last = recently_added.last?
|
||||||
|
if last && e.title_id == last[:entry].title_id
|
||||||
|
# A NamedTuple is immutable, so we have to cast it to a Hash first
|
||||||
|
last_hash = last.to_h
|
||||||
|
count = last_hash[:grouped_count].as(Int32)
|
||||||
|
last_hash[:grouped_count] = count + 1
|
||||||
|
# Setting the percentage to a negative value will hide the
|
||||||
|
# percentage badge on the card
|
||||||
|
last_hash[:percentage] = -1.0
|
||||||
|
recently_added[recently_added.size - 1] = RA.from last_hash
|
||||||
|
else
|
||||||
|
recently_added << {
|
||||||
|
entry: e,
|
||||||
|
percentage: e.load_percentage(username),
|
||||||
|
grouped_count: 1,
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
{
|
|
||||||
entry: entry,
|
recently_added[0..11]
|
||||||
percentage: percentage,
|
|
||||||
grouped_count: ary.size,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user