-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: public multiple photos from detroit (#3390)
* feat: add multiple photos * feat: add tests * feat: add images to seeds * fix: return array when no image * fix: shared helpers photos tests * fix: add class with variables to parent element * fix: make actions inside content section optional on desktop * fix: pass modalCloseInContent prop to listing view's ImageCard * fix: remove redundant image-card class * chore: upgrade ui-c * fix: remove redundant order column * fix: change font for drawer title * fix: remove default images value when editing
- Loading branch information
1 parent
edf3af5
commit d56de28
Showing
25 changed files
with
544 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,39 @@ | ||
import { Asset, Listing } from "@bloom-housing/backend-core/types" | ||
|
||
export const CLOUDINARY_BUILDING_LABEL = "cloudinaryBuilding" | ||
|
||
export const cloudinaryUrlFromId = (publicId: string, size = 400) => { | ||
const cloudName = process.env.cloudinaryCloudName || process.env.CLOUDINARY_CLOUD_NAME | ||
return `https://res.cloudinary.com/${cloudName}/image/upload/w_${size},c_limit,q_65/${publicId}.jpg` | ||
} | ||
|
||
export const imageUrlFromListing = (listing: Listing, size = 400) => { | ||
// Use the new `image` field | ||
export const getUrlForListingImage = (image: Asset, size = 400) => { | ||
if (!image) return null | ||
|
||
if (image.label == CLOUDINARY_BUILDING_LABEL) { | ||
return cloudinaryUrlFromId(image.fileId, size) | ||
} else { | ||
return image.fileId | ||
} | ||
} | ||
|
||
export const imageUrlFromListing = (listing: Listing, size = 400): string[] => { | ||
const imageAssets = | ||
listing?.images?.length && listing.images[0].image ? [listing.images[0].image] : listing?.assets | ||
listing?.images?.length && listing.images[0].image | ||
? listing.images | ||
.sort((imageA, imageB) => (imageA.ordinal ?? 10) - (imageB?.ordinal ?? 10)) | ||
.map((imageObj) => imageObj.image) | ||
: listing?.assets | ||
|
||
// Fallback to `assets` | ||
const cloudinaryBuilding = imageAssets?.find( | ||
(asset: Asset) => asset.label == "cloudinaryBuilding" | ||
)?.fileId | ||
if (cloudinaryBuilding) return cloudinaryUrlFromId(cloudinaryBuilding, size) | ||
const imageUrls = imageAssets | ||
?.filter( | ||
(asset: Asset) => asset.label === CLOUDINARY_BUILDING_LABEL || asset.label === "building" | ||
) | ||
?.map((asset: Asset) => { | ||
return asset.label === CLOUDINARY_BUILDING_LABEL | ||
? cloudinaryUrlFromId(asset.fileId, size) | ||
: asset.fileId | ||
}) | ||
|
||
return imageAssets?.find((asset: Asset) => asset.label == "building")?.fileId | ||
return imageUrls?.length > 0 ? imageUrls : [""] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+371 KB
...ixtures/cypress-automated-image-upload-46806882-b98d-49d7-ac83-8016ab4b2f08.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
sites/partners/src/components/listings/PaperListingDetails/sections/DetailListingPhotos.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { useContext } from "react" | ||
import { | ||
t, | ||
GridSection, | ||
GridCell, | ||
MinimalTable, | ||
TableThumbnail, | ||
} from "@bloom-housing/ui-components" | ||
import { getUrlForListingImage } from "@bloom-housing/shared-helpers" | ||
import { ListingContext } from "../../ListingContext" | ||
import { Asset } from "@bloom-housing/backend-core/types" | ||
|
||
const photoTableHeaders = { | ||
preview: "t.preview", | ||
fileName: "t.fileName", | ||
primary: "t.primary", | ||
} | ||
|
||
const DetailListingPhotos = () => { | ||
const listing = useContext(ListingContext) | ||
|
||
const listingFormPhotos = listing.images | ||
.sort((imageA, imageB) => imageA.ordinal - imageB.ordinal) | ||
.map((image) => image.image as Asset) | ||
|
||
const photoTableData = listingFormPhotos.map((image, index) => { | ||
return { | ||
preview: { | ||
content: ( | ||
<TableThumbnail> | ||
<img src={getUrlForListingImage(image)} alt={t("listings.sections.photoTitle")} /> | ||
</TableThumbnail> | ||
), | ||
}, | ||
fileName: { content: image.fileId.split("/").slice(-1).join() }, | ||
primary: { | ||
content: index == 0 ? t("listings.sections.photo.primaryPhoto") : "", | ||
}, | ||
} | ||
}) | ||
|
||
return ( | ||
<GridSection | ||
className="bg-primary-lighter" | ||
title={t("listings.sections.photoTitle")} | ||
grid={false} | ||
inset | ||
> | ||
<GridSection columns={1}> | ||
<GridCell> | ||
{listing.images.length > 0 ? ( | ||
<MinimalTable | ||
id="listingPhotoTable" | ||
headers={photoTableHeaders} | ||
data={photoTableData} | ||
/> | ||
) : ( | ||
<span className={"view-item__value"}>{t("t.none")}</span> | ||
)} | ||
</GridCell> | ||
</GridSection> | ||
</GridSection> | ||
) | ||
} | ||
|
||
export default DetailListingPhotos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.