diff --git a/package-lock.json b/package-lock.json index b9091b9..5976057 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,13 @@ { "name": "openrice_canada_frontend", - "version": "0.0.1", + "version": "0.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "openrice_canada_frontend", - "version": "0.0.1", + "version": "0.1.0", "dependencies": { - "@babel/plugin-proposal-private-property-in-object": "7.21.11", "@reduxjs/toolkit": "^1.9.7", "@supabase/supabase-js": "^2.38.4", "@testing-library/jest-dom": "^5.17.0", @@ -42,6 +41,7 @@ "web-vitals": "^2.1.4" }, "devDependencies": { + "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@types/google.maps": "^3.54.3", "@types/react-datepicker": "^4.19.1", "tailwindcss": "^3.3.3" @@ -664,6 +664,7 @@ "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.11.tgz", "integrity": "sha512-0QZ8qP/3RLDVBwBFoWAwCtgcDZJVwA5LUJRZU8x2YFfKNuFq161wK3cuGrALu5yiPu+vzwTAg/sMWVNeWeNyaw==", "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-property-in-object instead.", + "dev": true, "dependencies": { "@babel/helper-annotate-as-pure": "^7.18.6", "@babel/helper-create-class-features-plugin": "^7.21.0", @@ -19393,6 +19394,7 @@ "version": "7.21.11", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.11.tgz", "integrity": "sha512-0QZ8qP/3RLDVBwBFoWAwCtgcDZJVwA5LUJRZU8x2YFfKNuFq161wK3cuGrALu5yiPu+vzwTAg/sMWVNeWeNyaw==", + "dev": true, "requires": { "@babel/helper-annotate-as-pure": "^7.18.6", "@babel/helper-create-class-features-plugin": "^7.21.0", diff --git a/package.json b/package.json index 211250b..0c2f390 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "version": "0.1.0", "homepage": "https://openricecanadafrontend.vercel.app", "dependencies": { - "@babel/plugin-proposal-private-property-in-object": "7.21.11", "@reduxjs/toolkit": "^1.9.7", "@supabase/supabase-js": "^2.38.4", "@testing-library/jest-dom": "^5.17.0", @@ -83,6 +82,7 @@ ] }, "devDependencies": { + "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@types/google.maps": "^3.54.3", "@types/react-datepicker": "^4.19.1", "tailwindcss": "^3.3.3" diff --git a/src/pages/restaurant/RestaurantOverviewPage.tsx b/src/pages/restaurant/RestaurantOverviewPage.tsx index d3d72aa..bdad92a 100644 --- a/src/pages/restaurant/RestaurantOverviewPage.tsx +++ b/src/pages/restaurant/RestaurantOverviewPage.tsx @@ -26,8 +26,8 @@ const RestaurantOverviewPage: React.FC = () => { const [page, setPage] = useState("Reviews"); const [isShownAddReviewModal, setIsShownAddReviewModal] = useState(false); - const [photos, setPhotos] = useState([]); - const [menus, setMenus] = useState([]); + const [photos, setPhotos] = useState<{ id: string; src: string }[]>([]); + const [menus, setMenus] = useState<{ id: string; src: string }[]>([]); const [popUpOpen, setPopUpOpen] = useState(false); const [selectedImage, setSelectedImage] = useState(""); @@ -58,18 +58,18 @@ const RestaurantOverviewPage: React.FC = () => { useEffect(() => { if (id === "8879942f-fce4-41d2-8aab-3faeb8d8c909") { setPhotos( - reviews.map( - (review) => - `${process.env.REACT_APP_IMAGE_PREFIX}/reviews/${id}/${review.review_id}.jpg` - ) + reviews.map((review) => ({ + id: review.review_id, + src: `${process.env.REACT_APP_IMAGE_PREFIX}/photos/${id}/${review.review_id}.jpg`, + })) ); setMenus( reviews - .map( - (review) => - `${process.env.REACT_APP_IMAGE_PREFIX}/menus/${id}/${review.review_id}.jpg` - ) - .sort((a, b) => a.localeCompare(b)) + .map((review) => ({ + id: review.review_id, + src: `${process.env.REACT_APP_IMAGE_PREFIX}/menus/${id}/${review.review_id}.jpg`, + })) + .sort((a, b) => a.id.localeCompare(b.id)) ); } }, [id, reviews]); @@ -90,6 +90,26 @@ const RestaurantOverviewPage: React.FC = () => { useOnClickOutside(imageRef, () => setPopUpOpen(false)); useOnClickOutside(formRef, () => setIsShownAddReviewModal(false)); + const loadDefaultImage = (type: string, id: string) => { + if (type === "photo") { + setPhotos( + photos.map((photo) => + photo.id === id + ? { id, src: `${process.env.PUBLIC_URL}/error.svg` } + : photo + ) + ); + } else if (type === "menus") { + setMenus( + menus.map((menu) => + menu.id === id + ? { id, src: `${process.env.PUBLIC_URL}/error.svg` } + : menu + ) + ); + } + }; + const buttons = ["Reviews", "Photos", "Menus"]; if (!restaurantDetail) return null; @@ -173,14 +193,15 @@ const RestaurantOverviewPage: React.FC = () => { {photos.map((photo, index) => (
openPopUp(photo)} + onClick={() => openPopUp(photo.src)} key={`photo${index}`} > loadDefaultImage("photo", photo.id)} />
))} @@ -206,14 +227,15 @@ const RestaurantOverviewPage: React.FC = () => { {menus.map((menu, index) => (
openPopUp(menu)} + onClick={() => openPopUp(menu.src)} key={`menu${index}`} > loadDefaultImage("menu", menu.id)} />
))}