diff --git a/src/components/ImageDiff.jsx b/src/components/ImageDiff.jsx index 99f1473..a6044ad 100644 --- a/src/components/ImageDiff.jsx +++ b/src/components/ImageDiff.jsx @@ -2,6 +2,7 @@ import { useState } from 'react'; import { Table, Modal, Button, Tabs, Tab } from 'react-bootstrap'; import ReactCompareImage from 'react-compare-image'; import 'bootstrap/dist/css/bootstrap.min.css'; +import ImageTable from './ImageTable'; const HOST = 'https://s3-sj3.corp.adobe.com/milo'; @@ -53,7 +54,7 @@ const ImageDiff = ({ data, timestamp }) => { return (
Report Time: {timestamp}
-
Notes: no diff means the same, no image means not exist, number means how many diff images per device
+
Notes: a number specifies how many different images there are per device.
{Object.entries(groupedData).map(([segment, items], idx) => ( @@ -74,9 +75,7 @@ const ImageDiff = ({ data, timestamp }) => { {comparisons.map((item, index) => ( {item.order} - Stable version handleShow(`${HOST}/${item.a}`, '')} /> - Beta version handleShow(`${HOST}/${item.b}`, '')} /> - Differences version handleShow(`${HOST}/${item.diff}`, '')} /> + diff --git a/src/components/ImageTable.jsx b/src/components/ImageTable.jsx new file mode 100644 index 0000000..b8eea8f --- /dev/null +++ b/src/components/ImageTable.jsx @@ -0,0 +1,64 @@ +/* eslint-disable react/prop-types */ +import { useState, useEffect } from 'react'; + +// Function to check if image exists +const checkImageExists = (url) => { + return new Promise((resolve) => { + const img = new Image(); + img.onload = () => resolve(true); + img.onerror = () => resolve(false); + img.src = url; + }); +}; + +const ImageWithFallback = ({ src, alt, handleClick, style }) => { + const [imageExists, setImageExists] = useState(false); + + useEffect(() => { + let isMounted = true; + checkImageExists(src).then((exists) => { + if (isMounted) setImageExists(exists); + }); + return () => { + isMounted = false; + }; + }, [src]); + + if (!imageExists) { + if (alt.includes('Differences')) return 'No Difference'; + return 'No Image'; + } + + return {alt}; +}; + +const ImageTable = ({ HOST, item, handleShow }) => ( + <> + + handleShow(`${HOST}/${item.a}`, '')} + /> + + + handleShow(`${HOST}/${item.b}`, '')} + /> + + + handleShow(`${HOST}/${item.diff}`, '')} + /> + + +); + +export default ImageTable; diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index 471539c..6f2267d 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -1,5 +1,4 @@ import { useEffect, useState } from 'react'; - const directories = ['sot', 'milo', 'feds', 'caas', 'uar', 'uar-ai']; const HomePage = () => { @@ -26,17 +25,12 @@ const HomePage = () => { }; return ( -
-
-