From 1ec8dcbfdab19c8bf88d9781e9e22ca03b0ac242 Mon Sep 17 00:00:00 2001 From: Leeingnyo Date: Sun, 26 Dec 2021 01:50:55 +0900 Subject: [PATCH] Use sort_title, sort_titles in title page --- src/library/title.cr | 7 ++++++- src/util/util.cr | 12 ++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/library/title.cr b/src/library/title.cr index d1520be..9eacf4e 100644 --- a/src/library/title.cr +++ b/src/library/title.cr @@ -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 diff --git a/src/util/util.cr b/src/util/util.cr index 7278bb2..2814c6c 100644 --- a/src/util/util.cr +++ b/src/util/util.cr @@ -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