Skip to content

Commit

Permalink
Resources render the last image vs the first
Browse files Browse the repository at this point in the history
Since we are not displaying multiple images in the
front facing app yet, we can expose the last image
as the featured image. Same with admin, when they
upload an image for a resource, that image will be
displayed in the front facing app.

Note that we may add an image slider sooner or later.
  • Loading branch information
DeeTheDev committed Nov 27, 2024
1 parent 5ce63c4 commit 84ff1a1
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/suma/admin_api/commerce_offerings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DetailedOfferingEntity < OfferingEntity
expose :fulfillment_confirmation, with: TranslatedTextEntity
expose :fulfillment_options, with: OfferingFulfillmentOptionEntity
expose :begin_fulfillment_at
expose :image, with: ImageEntity, &self.delegate_to(:images?, :first)
expose :image, with: ImageEntity, &self.delegate_to(:images?, :last)
expose :offering_products, with: OfferingProductEntity
expose :orders, with: OrderInOfferingEntity
expose :programs, with: ProgramEntity
Expand Down
2 changes: 1 addition & 1 deletion lib/suma/admin_api/commerce_products.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DetailedEntity < ProductEntity
expose :offerings, with: OfferingEntity
expose :orders, with: OrderEntity
expose :offering_products, with: OfferingProductWithOfferingEntity
expose :image, with: ImageEntity, &self.delegate_to(:images?, :first)
expose :image, with: ImageEntity, &self.delegate_to(:images?, :last)
expose :vendor_service_categories, with: VendorServiceCategoryEntity
end

Expand Down
2 changes: 1 addition & 1 deletion lib/suma/admin_api/programs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Suma::AdminAPI::Programs < Suma::AdminAPI::V1
class DetailedProgramEntity < ProgramEntity
include Suma::AdminAPI::Entities
include AutoExposeDetail
expose :image, with: ImageEntity, &self.delegate_to(:images?, :first)
expose :image, with: ImageEntity, &self.delegate_to(:images?, :last)
expose :commerce_offerings, with: OfferingEntity
expose :vendor_services, with: VendorServiceEntity
expose :anon_proxy_vendor_configurations, as: :configurations, with: VendorConfigurationEntity
Expand Down
2 changes: 1 addition & 1 deletion lib/suma/admin_api/vendor_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DetailedVendorServiceEntity < VendorServiceEntity
expose :vendor_service_categories, as: :categories, with: VendorServiceCategoryEntity
expose :rates, with: VendorServiceRateEntity
expose :mobility_trips, with: DetailedMobilityTripEntity
expose :image, with: ImageEntity, &self.delegate_to(:images?, :first)
expose :image, with: ImageEntity, &self.delegate_to(:images?, :last)
end

resource :vendor_services do
Expand Down
2 changes: 1 addition & 1 deletion lib/suma/admin_api/vendors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DetailedVendorEntity < VendorEntity
expose :services, with: VendorServiceEntity
expose :products, with: ProductEntity
expose :configurations, with: VendorConfigurationEntity
expose :image, with: ImageEntity, &self.delegate_to(:images?, :first)
expose :image, with: ImageEntity, &self.delegate_to(:images?, :last)
end

resource :vendors do
Expand Down
3 changes: 1 addition & 2 deletions lib/suma/api/anon_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ class AnonProxyVendorAccountEntity < BaseEntity
instance.latest_access_code_is_recent? ? instance.latest_access_code_magic_link : nil
end
expose :vendor_name, &self.delegate_to(:configuration, :vendor, :name)
expose :vendor_slug, &self.delegate_to(:configuration, :vendor, :slug)
expose :vendor_image, with: ImageEntity, &self.delegate_to(:configuration, :vendor, :images, :first)
expose :vendor_image, with: ImageEntity, &self.delegate_to(:configuration, :vendor, :images?, :last)
end

class MutationAnonProxyVendorAccountEntity < AnonProxyVendorAccountEntity
Expand Down
6 changes: 3 additions & 3 deletions lib/suma/api/commerce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class OfferingEntity < BaseEntity
expose_translated :fulfillment_confirmation
expose_translated :fulfillment_instructions
expose :period_end, as: :closes_at
expose :image, with: Suma::API::Entities::ImageEntity, &self.delegate_to(:images?, :first)
expose :image, with: Suma::API::Entities::ImageEntity, &self.delegate_to(:images?, :last)
expose :rel_app_link, as: :app_link
end

Expand All @@ -278,7 +278,7 @@ class BaseOfferingProductEntity < BaseEntity
expose :offering_id
expose :product_id, &self.delegate_to(:product, :id)
expose :vendor, with: VendorEntity, &self.delegate_to(:product, :vendor)
expose :images, with: Suma::API::Entities::ImageEntity, &self.delegate_to(:product, :images?)
expose :image, with: Suma::API::Entities::ImageEntity, &self.delegate_to(:product, :images?, :last)
end

class PricedOfferingProductEntity < BaseOfferingProductEntity
Expand Down Expand Up @@ -434,7 +434,7 @@ class OrderHistoryItemEntity < BaseEntity
expose :quantity
expose_translated :name, &self.delegate_to(:offering_product, :product, :name)
expose_translated :description, &self.delegate_to(:offering_product, :product, :description)
expose :image, with: ImageEntity, &self.delegate_to(:offering_product, :product, :images?, :first)
expose :image, with: ImageEntity, &self.delegate_to(:offering_product, :product, :images?, :last)
expose :customer_price, with: MoneyEntity, &self.delegate_to(:offering_product, :customer_price)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/suma/api/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MemberPreferencesEntity < BaseEntity
class ProgramEnrollmentEntity < BaseEntity
expose_translated :name, &self.delegate_to(:program, :name)
expose_translated :description, &self.delegate_to(:program, :description)
expose :image, with: ImageEntity, &self.delegate_to(:program, :image?)
expose :image, with: ImageEntity, &self.delegate_to(:program, :images?, :last)
expose :period_begin, &self.delegate_to(:program, :period, :begin)
expose :period_end, &self.delegate_to(:program, :period, :end)
expose :app_link, &self.delegate_to(:program, :app_link)
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/pages/FoodCart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ function CartItem({ offeringId, product, vendor }) {
isDiscounted,
displayableCashPrice,
undiscountedPrice,
images,
image,
} = product;
return (
<Stack direction="horizontal" gap={3} className="align-items-start">
<Link to={`/product/${offeringId}/${productId}`}>
<SumaImage image={images[0]} className="w-100" w={100} h={100} />
<SumaImage image={image} className="w-100" w={100} h={100} />
</Link>
<div>
<Link to={`/product/${offeringId}/${productId}`}>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/pages/FoodCheckout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ function CheckoutItem({ item }) {
const { product, quantity } = item;
return (
<Stack direction="horizontal" gap={3} className="align-items-start">
<SumaImage image={product.images[0]} className="rounded" w={80} h={80} />
<SumaImage image={product.image} className="rounded" w={80} h={80} />
{product.outOfStock ? (
<Stack>
<h6 className="mb-2">{product.name}</h6>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/pages/FoodCheckoutConfirmation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function Item({ item }) {
const { product, quantity } = item;
return (
<Stack direction="horizontal" gap={3} className="mb-3 align-items-start">
<SumaImage image={product.images[0]} className="rounded" w={90} h={90} />
<SumaImage image={product.image} className="rounded" w={90} h={90} />
<Stack>
<p className="mb-0 lead">{product.name}</p>
<p className="text-secondary mb-0">
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/pages/FoodDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function FoodDetails() {
</Row>
</LayoutContainer>
<SumaImage
image={product.images[0]}
image={product.image}
className="w-100"
params={{ crop: "center" }}
h={325}
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/pages/FoodList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ export default function FoodList() {
}

function Product({ product, offeringId, cart }) {
const { productId, name, images, outOfStock } = product;
const { productId, name, image, outOfStock } = product;
return (
<Col
xs={6}
className="mb-4 border-bottom border-secondary border-opacity-50 position-relative"
>
<SumaImage image={images[0]} className="w-100" w={225} h={150} />
<SumaImage image={image} className="w-100" w={225} h={150} />
<h5 className="mb-2 mt-2">{name}</h5>
<p className="my-2">{product.vendor.name}</p>
{outOfStock ? (
Expand Down

0 comments on commit 84ff1a1

Please sign in to comment.