From 23240005a2ae26ede7a1d691e80f3fe89bd6904d Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 23 Jan 2024 04:06:58 -0800 Subject: [PATCH] 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. --- app/models/closet_list.rb | 7 +++---- app/views/items/_item_header.haml | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/closet_list.rb b/app/models/closet_list.rb index 20665032..ea303db9 100644 --- a/app/models/closet_list.rb +++ b/app/models/closet_list.rb @@ -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 diff --git a/app/views/items/_item_header.haml b/app/views/items/_item_header.haml index b8cd497e..80b27872 100644 --- a/app/views/items/_item_header.haml +++ b/app/views/items/_item_header.haml @@ -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