Use sort_title, sort_titles in title page

This commit is contained in:
Leeingnyo 2021-12-26 01:50:55 +09:00
parent 8fea35fa51
commit 1ec8dcbfda
2 changed files with 12 additions and 7 deletions

View File

@ -253,7 +253,12 @@ class Title
end
def sorted_titles(username, opt : SortOptions? = nil)
titles
if opt.nil?
opt = SortOptions.from_info_json @dir, username
end
# Helper function from src/util/util.cr
sort_titles titles, opt.not_nil!, username
end
# Get all entries, including entries in nested titles

View File

@ -91,21 +91,21 @@ def sort_titles(titles : Array(Title), opt : SortOptions, username : String)
case opt.method
when .time_modified?
ary.sort! { |a, b| (a.mtime <=> b.mtime).or \
compare_numerically a.title, b.title }
ary.sort { |a, b| (a.mtime <=> b.mtime).or \
compare_numerically a.sort_title, b.sort_title }
when .progress?
ary.sort! do |a, b|
ary.sort do |a, b|
(a.load_percentage(username) <=> b.load_percentage(username)).or \
compare_numerically a.title, b.title
compare_numerically a.sort_title, b.sort_title
end
when .title?
ary.sort! { |a, b| compare_numerically a.title, b.title }
ary.sort { |a, b| compare_numerically a.sort_title, b.sort_title }
else
unless opt.method.auto?
Logger.warn "Unknown sorting method #{opt.not_nil!.method}. Using " \
"Auto instead"
end
ary.sort! { |a, b| compare_numerically a.title, b.title }
ary.sort { |a, b| compare_numerically a.sort_title, b.sort_title }
end
ary.reverse! unless opt.not_nil!.ascend