From db041fea88f07d16e25b453572a8563ba614a539 Mon Sep 17 00:00:00 2001 From: Floyd Wang Date: Thu, 24 Oct 2024 18:15:12 +0800 Subject: [PATCH] table: Add default option to `perform_sort` (#379) --- crates/story/src/table_story.rs | 9 +++------ crates/ui/src/table.rs | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/story/src/table_story.rs b/crates/story/src/table_story.rs index cb7afa1f..6bf723cb 100644 --- a/crates/story/src/table_story.rs +++ b/crates/story/src/table_story.rs @@ -439,12 +439,9 @@ impl TableDelegate for StockTableDelegate { if let Some(col) = self.columns.get_mut(col_ix) { match col.id.as_ref() { - "id" => self.stocks.sort_by(|a, b| { - if sort == ColSort::Ascending { - a.id.cmp(&b.id) - } else { - b.id.cmp(&a.id) - } + "id" => self.stocks.sort_by(|a, b| match sort { + ColSort::Descending => b.id.cmp(&a.id), + _ => a.id.cmp(&b.id), }), _ => {} } diff --git a/crates/ui/src/table.rs b/crates/ui/src/table.rs index f8152405..2084d088 100644 --- a/crates/ui/src/table.rs +++ b/crates/ui/src/table.rs @@ -506,7 +506,7 @@ where let sort = sort.unwrap(); let sort = match sort { - ColSort::Ascending => ColSort::Descending, + ColSort::Ascending => ColSort::Default, ColSort::Descending => ColSort::Ascending, ColSort::Default => ColSort::Descending, };