diff --git a/api/lighthouse-report.js b/api/lighthouse-report.js index d8b85af..7123cca 100644 --- a/api/lighthouse-report.js +++ b/api/lighthouse-report.js @@ -11,6 +11,14 @@ exports.handler = function(event, context, callback) { } const apiKey = process.env.GOOGLE_CLOUD_API_KEY; + + if (!apiKey) { + callback(null, { + statusCode: 500, + body: JSON.stringify({ error: 'API key (GOOGLE_CLOUD_API_KEY) not set'}), + }); + } + const endpoint = `https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=${encodeURIComponent(url)}&category=PERFORMANCE&category=ACCESSIBILITY&category=BEST_PRACTICES&category=SEO&category=PWA&strategy=mobile&key=${apiKey}`; axios.get(endpoint) diff --git a/src/components/misc/Loader.tsx b/src/components/misc/Loader.tsx new file mode 100644 index 0000000..02230cc --- /dev/null +++ b/src/components/misc/Loader.tsx @@ -0,0 +1,93 @@ +import styled from 'styled-components'; + +import { StyledCard } from 'components/Form/Card'; +import Heading from 'components/Form/Heading'; +import colors from 'styles/colors'; + +const LoaderContainer = styled(StyledCard)` + margin: 0 auto 1rem auto; + width: 95vw; + position: relative; + transition: all 0.2s ease-in-out; + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; + gap: 2rem; + height: 50vh; + transition: all 0.3s ease-in-out; + &.flex { + display: flex; + } + &.finished { + height: 0; + overflow: hidden; + opacity: 0; + margin: 0; + padding: 0; + svg { width: 0; } + h4 { font-size: 0; } + } + &.hide { + display: none; + } +`; + +const StyledSvg = styled.svg` + width: 200px; + margin: 0 auto; + path { + fill: ${colors.primary}; + &:nth-child(2) { opacity: 0.8; } + &:nth-child(3) { opacity: 0.5; } + } +`; + +const Loader = (props: { show: boolean }): JSX.Element => { + return ( + + Fetching data... + + + + + + + + + + + + + ); +} + +export default Loader; + + + diff --git a/src/pages/Results.tsx b/src/pages/Results.tsx index 20ba495..a9056bd 100644 --- a/src/pages/Results.tsx +++ b/src/pages/Results.tsx @@ -13,6 +13,7 @@ import { RowProps } from 'components/Form/Row'; import ErrorBoundary from 'components/misc/ErrorBoundary'; import docs from 'utils/docs'; +import Loader from 'components/misc/Loader'; import ServerLocationCard from 'components/Results/ServerLocation'; import ServerInfoCard from 'components/Results/ServerInfo'; @@ -102,8 +103,7 @@ const Results = (): JSX.Element => { const [ addressType, setAddressType ] = useState('empt'); const { address } = useParams(); - const [ loadingJobs, setLoadingJobs ] = useState(initialJobs); - + const [loadingJobs, setLoadingJobs] = useState(initialJobs); const [modalOpen, setModalOpen] = useState(false); const [modalContent, setModalContent] = useState(<>); @@ -496,6 +496,7 @@ const Results = (): JSX.Element => { { address?.includes(window?.location?.hostname || 'web-check.as93.net') && } + job.state !== 'loading').length < 5} />