Skip to content

Commit

Permalink
Build page updates (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivntsng authored Oct 30, 2024
1 parent b29506b commit b7a6dd1
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions frontend/src/components/products/ProductPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ const ProductPage: React.FC<ProductPageProps> = ({
null,
);

const extractArtifactId = (imageUrl: string) => {
// Try matching the production URL pattern
const prodMatch = imageUrl.match(/\/artifacts\/media\/([^/]+)\/([^/]+)/);
if (prodMatch) return prodMatch[2];

// Try matching the local development URL pattern
const localMatch = imageUrl.match(/\/uploads\/([^/]+)/);
if (localMatch) return localMatch[1];

return null;
};

const handleDeleteImage = async (imageUrl: string, index: number) => {
if (!creatorInfo?.can_edit) {
addErrorAlert("You don't have permission to delete this image");
Expand All @@ -176,12 +188,10 @@ const ProductPage: React.FC<ProductPageProps> = ({
setDeletingImageIndex(index);

try {
const artifactId = imageUrl.match(
/\/artifacts\/media\/([^/]+)\/([^/]+)/,
)?.[2];
const artifactId = extractArtifactId(imageUrl);

if (!artifactId) {
addErrorAlert("Invalid image URL format");
addErrorAlert("Could not extract artifact ID from image URL");
setDeletingImageIndex(null);
return;
}
Expand Down Expand Up @@ -383,12 +393,10 @@ const ProductPage: React.FC<ProductPageProps> = ({
}

try {
const artifactId = imageUrl.match(
/\/artifacts\/media\/([^/]+)\/([^/]+)/,
)?.[2];
const artifactId = extractArtifactId(imageUrl);

if (!artifactId) {
addErrorAlert("Invalid image URL format");
addErrorAlert("Could not extract artifact ID from image URL");
return;
}

Expand Down

0 comments on commit b7a6dd1

Please sign in to comment.