Skip to content

Commit

Permalink
fix: 5830 - sorted "more photos" by timestamp (#5843)
Browse files Browse the repository at this point in the history
Impacted file:
* `product_cards_helper.dart`: sorted "more photos" by timestamp
  • Loading branch information
monsieurtanuki authored Nov 12, 2024
1 parent bab4fd8 commit 3665f05
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/smooth_app/lib/helpers/product_cards_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,9 @@ List<ProductImage> getRawProductImages(
final Product product,
final ImageSize imageSize,
) {
final List<ProductImage> result = <ProductImage>[];
final List<ProductImage>? rawImages = product.getRawImages();
if (rawImages == null) {
return result;
return <ProductImage>[];
}
final Map<int, ProductImage> map = <int, ProductImage>{};
for (final ProductImage productImage in rawImages) {
Expand All @@ -439,10 +438,22 @@ List<ProductImage> getRawProductImages(
}
map[imageId] = productImage;
}
final List<int> sortedIds = List<int>.of(map.keys);
sortedIds.sort();
for (final int id in sortedIds) {
result.add(map[id]!);
}
final List<ProductImage> result = List<ProductImage>.of(map.values);
result.sort(
(
final ProductImage a,
final ProductImage b,
) {
final int result = (a.uploaded?.millisecondsSinceEpoch ?? 0).compareTo(
b.uploaded?.millisecondsSinceEpoch ?? 0,
);
if (result != 0) {
return result;
}
return (int.tryParse(a.imgid ?? '0') ?? 0).compareTo(
int.tryParse(b.imgid ?? '0') ?? 0,
);
},
);
return result;
}

0 comments on commit 3665f05

Please sign in to comment.