Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
fix: pass location into LandingBanner
Browse files Browse the repository at this point in the history
  • Loading branch information
aswanson-nr committed May 6, 2022
1 parent f5706c7 commit 4765664
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 51 deletions.
4 changes: 3 additions & 1 deletion src/components/LandingBanner/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';

import Breadcrumbs from '../../components/Breadcrumbs';
import InstallButton from '../../components/InstallButton';
Expand All @@ -9,7 +10,7 @@ import BannerBackground from './BannerBackground';

const IMAGE_DISPLAY_BREAKPOINT = '1200px';

const LandingBanner = ({ quickstart, className }) => {
const LandingBanner = ({ quickstart, className, location }) => {
const [imgStyle, setImgStyle] = useState({});

const breadcrumbs = [
Expand Down Expand Up @@ -195,6 +196,7 @@ const LandingBanner = ({ quickstart, className }) => {

LandingBanner.propTypes = {
quickstarts: quickstart.isRequired,
location: PropTypes.object.isRequired,
};

export default LandingBanner;
53 changes: 3 additions & 50 deletions src/templates/QuickstartDetails.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Button, Icon, Link, useTessen } from '@newrelic/gatsby-theme-newrelic';
import { QUICKSTARTS_REPO, SHIELD_LEVELS } from '../data/constants';
import React, { useEffect, useState } from 'react';
import { useTessen } from '@newrelic/gatsby-theme-newrelic';
import React from 'react';

import Breadcrumbs from '../components/Breadcrumbs';
import IOSeo from '../components/IOSeo';
import InstallButton from '../components/InstallButton';
import PageLayout from '../components/PageLayout';
import PropTypes from 'prop-types';
import { css } from '@emotion/react';
Expand All @@ -28,20 +25,8 @@ const layoutContentSpacing = css`
`;

const QuickstartDetails = ({ data, location }) => {
const [imgStyle, setImgStyle] = useState({});

const quickstart = data.quickstarts;
const quickstartUrl = quickstart.packUrl || QUICKSTARTS_REPO;
const tessen = useTessen();
const breadcrumbs = [
{
name: 'Instant Observability (I/O)',
url: '/',
},
{
name: quickstart.title,
},
];
const quickStartMeta = [
{
name: 'quick_start_name',
Expand Down Expand Up @@ -69,39 +54,6 @@ const QuickstartDetails = ({ data, location }) => {
});
};

// get image resolution from URL
const getURLMeta = async (url) => {
const img = new Image();
img.src = url;
const { width, height } = await new Promise((resolve) => {
img.onload = function () {
resolve({
width: this.width,
height: this.height,
});
};
});
return { width, height };
};

const getImgStyle = async () => {
const { width, height } = await getURLMeta(quickstart.logoUrl);
const style = {};
// if image is rectangle
if (width > height) {
style.width = '';
style.height = '';
} else {
style.width = '80px';
style.height = '80px';
}
setImgStyle(style);
};

useEffect(() => {
getImgStyle();
}, [quickstart.logoUrl]);

return (
<>
<IOSeo
Expand Down Expand Up @@ -129,6 +81,7 @@ const QuickstartDetails = ({ data, location }) => {
margin: 0 var(--page-margin);
`}
quickstart={quickstart}
location={location}
/>
</PageLayout.Header>

Expand Down

0 comments on commit 4765664

Please sign in to comment.