From 8d728c84d1dcef5a599af5a70bf886a3866e587b Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Sun, 15 Feb 2026 20:49:42 -0800 Subject: [PATCH] [WV2] Add zone badges to search results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Show which zones each item occupies in search result cards. Zone badges appear as small, muted labels (e.g., "Background", "Hat", "Static") after the NC/NP and date badges. Items that occupy multiple zones show multiple badges. Zone badges only appear in search results, not in outfit items, since outfit items are already grouped by zone which provides sufficient context. Implementation: - Created zones badge partial to render zone labels from item appearances - Updated controller to load item appearances with zone data for search results - Pass appearance data through the rendering chain (search_results → item_card → item_card_content) - Added subtle CSS styling for zone badges (light gray background, gray text) Co-Authored-By: Claude Sonnet 4.5 --- app/controllers/wardrobe_controller.rb | 6 ++++++ app/views/wardrobe/items/_item_card.html.haml | 4 ++-- app/views/wardrobe/items/_item_card_content.html.haml | 2 ++ app/views/wardrobe/items/_search_results.html.haml | 3 ++- app/views/wardrobe/items/badges/_zones.html.haml | 4 ++++ 5 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 app/views/wardrobe/items/badges/_zones.html.haml diff --git a/app/controllers/wardrobe_controller.rb b/app/controllers/wardrobe_controller.rb index bff57393..30bbadf0 100644 --- a/app/controllers/wardrobe_controller.rb +++ b/app/controllers/wardrobe_controller.rb @@ -105,6 +105,12 @@ class WardrobeController < ApplicationController ) @query = Item::Search::Query.from_params(query_params, current_user) @search_results = @query.results.paginate(page: params.dig(:q, :page), per_page: 30) + + # Load appearances for search results to get zone information + target = @alt_style || @pet_type + if target + @appearances_by_item_id = Item.appearances_for(@search_results, target, swf_asset_includes: [:zone]) + end end render layout: false diff --git a/app/views/wardrobe/items/_item_card.html.haml b/app/views/wardrobe/items/_item_card.html.haml index 73691680..dab6bd2f 100644 --- a/app/views/wardrobe/items/_item_card.html.haml +++ b/app/views/wardrobe/items/_item_card.html.haml @@ -4,11 +4,11 @@ - if defined?(zone_id) && zone_id %label.item-card-label %input.visually-hidden{type: "radio", name: "zone_#{zone_id}", checked: is_worn || nil, "aria-label": item.name} - = render "wardrobe/items/item_card_content", item: item + = render "wardrobe/items/item_card_content", item: item, appearance: local_assigns[:appearance] - else %label.item-card-label %input.visually-hidden{type: "checkbox", checked: is_worn || nil, "aria-label": item.name} - = render "wardrobe/items/item_card_content", item: item + = render "wardrobe/items/item_card_content", item: item, appearance: local_assigns[:appearance] - if is_worn = button_to @wardrobe_path, method: :get, class: "item-hide-button", title: "Hide #{item.name}", "aria-label": "Hide #{item.name}" do đŸ‘ī¸â€đŸ—¨ī¸ diff --git a/app/views/wardrobe/items/_item_card_content.html.haml b/app/views/wardrobe/items/_item_card_content.html.haml index 284498a3..2ff1cc03 100644 --- a/app/views/wardrobe/items/_item_card_content.html.haml +++ b/app/views/wardrobe/items/_item_card_content.html.haml @@ -7,4 +7,6 @@ %span{aria: {label: "Item info"}} â„šī¸ .item-badges = render "items/badges/kind", item: item + - if local_assigns[:appearance] + = render "wardrobe/items/badges/zones", appearance: appearance = render "items/badges/first_seen", item: item diff --git a/app/views/wardrobe/items/_search_results.html.haml b/app/views/wardrobe/items/_search_results.html.haml index 45352010..00d3f0d9 100644 --- a/app/views/wardrobe/items/_search_results.html.haml +++ b/app/views/wardrobe/items/_search_results.html.haml @@ -4,7 +4,8 @@ %ul.search-results-list - @search_results.each do |item| - = render "items/item_card", item: item + - appearance = @appearances_by_item_id&.dig(item.id) + = render "items/item_card", item: item, appearance: appearance = will_paginate @search_results, param_name: "q[page]", params: @outfit.wardrobe_params.merge(q: params[:q]) diff --git a/app/views/wardrobe/items/badges/_zones.html.haml b/app/views/wardrobe/items/badges/_zones.html.haml new file mode 100644 index 00000000..6c25671d --- /dev/null +++ b/app/views/wardrobe/items/badges/_zones.html.haml @@ -0,0 +1,4 @@ +- if local_assigns[:appearance] && appearance.present? + - zones = appearance.swf_assets.map(&:zone).uniq.sort_by(&:label) + - zones.each do |zone| + %span.item-badge= zone.label