Skip to content

Commit fe63a25

Browse files
committed
combine images/commissions (thanks claude)
1 parent 848dd02 commit fe63a25

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

app/views/content/form/gallery/_panel.html.erb

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
regular_images = raw_model.image_uploads.ordered.to_a
66
basil_images = (@basil_images || []).sort_by(&:position)
77

8-
# Keep track of regular and AI images separately for display
9-
images = regular_images
10-
118
# Calculate total images for display purposes
129
total_images = regular_images.count + basil_images.count
1310

@@ -22,7 +19,9 @@
2219
id: image.id,
2320
type: 'image_upload',
2421
data: image,
25-
pinned: image.pinned?
22+
pinned: image.pinned?,
23+
created_at: image.created_at,
24+
position: image.position || 999999
2625
}
2726
end
2827

@@ -31,19 +30,26 @@
3130
id: commission.id,
3231
type: 'basil_commission',
3332
data: commission,
34-
pinned: commission.pinned?
33+
pinned: commission.pinned?,
34+
created_at: commission.saved_at,
35+
position: commission.position || 999999
3536
}
3637
end
3738

38-
# If there's a pinned image, move it to the front
39-
if pinned_image
40-
combined_images.sort_by! { |img| img[:pinned] ? 0 : 1 }
39+
# Sort by position (using pinned status as priority)
40+
combined_images.sort_by! do |img|
41+
# The pinned flag is the primary sort key
42+
pinned_sort = img[:pinned] ? 0 : 1
43+
# Position is the secondary sort key
44+
position_sort = img[:position] || 999999
45+
# Created date is tertiary sort
46+
[pinned_sort, position_sort, img[:created_at] || Time.current]
4147
end
4248
%>
4349

4450
<div class="row">
4551
<div class="col s12">
46-
<% if images.any? || basil_images.any? %>
52+
<% if combined_images.any? %>
4753
<!-- Gallery preview section -->
4854
<div class="gallery-preview-section">
4955
<h5 class="gallery-section-title">

0 commit comments

Comments
 (0)