Skip to content

Commit

Permalink
list does not match website when sorting by pledge (#579)
Browse files Browse the repository at this point in the history
## Summary
When sorting by pledge, goals were sorted grouped by pledge amounts. The
sort order within seemed undefined.

Also used the opportunity to clean the code somewhat using
`sorted(using:)` where multiple comparators may be provided.

## Validation
Ran app in simulator.
Compared before and after to list when sorting on the website.


Fixes #578
  • Loading branch information
krugerk authored Dec 30, 2024
1 parent 971f9e5 commit 3620b9e
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions BeeSwift/Gallery/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,22 +357,21 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
}

func sortedGoals(_ goals: any Sequence<Goal>) -> [Goal] {
return goals.sorted(by: { (goal1, goal2) -> Bool in
if let selectedGoalSort = UserDefaults.standard.value(forKey: Constants.selectedGoalSortKey) as? String {
if selectedGoalSort == Constants.nameGoalSortString {
return goal1.slug < goal2.slug
}
else if selectedGoalSort == Constants.recentDataGoalSortString {
return goal1.lastTouch > goal2.lastTouch
}
else if selectedGoalSort == Constants.pledgeGoalSortString {
return goal1.pledge > goal2.pledge
}
}

// urgencykey is guaranteed to result in goals sorting into the canonical order
return goal1.urgencyKey < goal2.urgencyKey
})
let selectedGoalSort = UserDefaults.standard.value(forKey: Constants.selectedGoalSortKey) as? String ?? Constants.urgencyGoalSortString

switch selectedGoalSort {
case Constants.nameGoalSortString:
return goals.sorted(using: [SortDescriptor(\.slug),
SortDescriptor(\.urgencyKey)])
case Constants.recentDataGoalSortString:
return goals.sorted(using: [SortDescriptor(\.lastTouch, order: .reverse),
SortDescriptor(\.urgencyKey)])
case Constants.pledgeGoalSortString:
return goals.sorted(using: [SortDescriptor(\.pledge, order: .reverse),
SortDescriptor(\.urgencyKey)])
default:
return goals.sorted(using: SortDescriptor(\.urgencyKey))
}
}

func updateFilteredGoals() {
Expand Down

0 comments on commit 3620b9e

Please sign in to comment.