Skip to content

Commit

Permalink
SDK usage
Browse files Browse the repository at this point in the history
  • Loading branch information
devpato committed May 6, 2024
1 parent 32fcd5c commit b2abd23
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
3 changes: 1 addition & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
VITE_CLOUD_NAME=eventography
VITE_CLOUDINARY_CLOUD_FOLDER_URL=https://res.cloudinary.com/eventography/image/upload/q_auto/v1712555809/events/
VITE_CLOUD_NAME=eventography
3 changes: 1 addition & 2 deletions src/CloudinaryUploadWidget.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useEffect, useState, useCallback } from "react";
import PropTypes from "prop-types";
import { updateEventData } from "./helpers/firebase";
import { imageOptimizationUrl } from "./helpers/cloudinaryHelpers";
import { getEventIdFromUrl } from "./helpers/urlHelpers";

function CloudinaryUploadWidget({ uwConfig, docSnap }) {
Expand Down Expand Up @@ -75,7 +74,7 @@ function CloudinaryUploadWidget({ uwConfig, docSnap }) {
} else {
setImages(prevImages => [
...prevImages,
imageOptimizationUrl(img.uploadInfo.url, "q_auto"),
img.uploadInfo.url,
]);
setThumbnails(prevThumbnails => [
...prevThumbnails,
Expand Down
12 changes: 9 additions & 3 deletions src/Gallery.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ import { useEffect, useState } from 'react';
import './Gallery.css';
import { getEventIdFromUrl } from './helpers/urlHelpers';
import { getEventData } from './helpers/firebase';
import { AdvancedImage } from '@cloudinary/react';
import {Cloudinary} from "@cloudinary/url-gen";

const Gallery = () => {
const [showFullImage, setShowFullImage] = useState(false);
const [selectedImage, setSelectedImage] = useState(null);
const [docSnap, setDocSnap] = useState(null);
const [loadingStates, setLoadingStates] = useState([]);
const cld = new Cloudinary({
cloud: {
cloudName: import.meta.env.VITE_CLOUD_NAME
}
});

const eventId = getEventIdFromUrl(window.location.pathname);

Expand All @@ -26,8 +33,7 @@ const Gallery = () => {

const handleThumbnailClick = (imgUrl) => {
const imageName = imgUrl.substring(imgUrl.lastIndexOf('/') + 1);
const imageUrlPath = import.meta.env.VITE_CLOUDINARY_CLOUD_FOLDER_URL;
const urlBuilder = `${imageUrlPath}${eventId}/${imageName}`;
const urlBuilder = `events/${eventId}/${imageName}`;
setShowFullImage(true);
setSelectedImage(urlBuilder);
};
Expand Down Expand Up @@ -56,7 +62,7 @@ const Gallery = () => {
<button className="close-btn" onClick={handleCloseFullImage}>
Close
</button>
<img src={selectedImage} alt="Full Size" className="full-image" />
<AdvancedImage cldImg={cld.image(selectedImage).delivery('q_auto').format('auto')} className="full-image"/>
</div>
)}
{!showFullImage && docSnap?.thumbnails?.length > 0 ? (
Expand Down
15 changes: 0 additions & 15 deletions src/helpers/cloudinaryHelpers.js

This file was deleted.

0 comments on commit b2abd23

Please sign in to comment.