Oops, fix bug that would sometimes flip own/want in the item bulk menu

If your first wanted list was created before your first owned list,
then `false` would come before `true` in the keys of
`current_user_lists`.

I both fixed this to be more consistent at the model level, because who
likes unpredictable behavior? But also downstream at the view I
hardcoded that true should come before false, because that's a UI
concern that I want to be encoded in the view regardless of what's
upstream.
This commit is contained in:
Emi Matchu 2024-01-23 04:06:58 -08:00
parent 929c825b23
commit 23240005a2
2 changed files with 5 additions and 5 deletions

View file

@ -88,10 +88,9 @@ class ClosetList < ApplicationRecord
end
def self.group_by_owned
h = all.group_by(&:hangers_owned?)
h[true] ||= []
h[false] ||= []
h
{true => [], false => []}.tap do |h|
all.each { |list| h[list.hangers_owned?] << list}
end
end
include VisibilityMethods

View file

@ -42,7 +42,8 @@
user_closet_hangers_path(current_user))
= form_tag update_quantities_user_item_closet_hangers_path(:user_id => current_user, :item_id => item), :method => :put do
.closet-hangers-ownership-groups
- current_user_lists.each do |owned, lists|
- [true, false].each do |owned|
- lists = current_user_lists[owned]
%div
%h4= closet_lists_group_name(:you, owned)
%ul