Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS - Fix Gatsby image type #7702

Merged
merged 5 commits into from
Sep 8, 2022
Merged

TS - Fix Gatsby image type #7702

merged 5 commits into from
Sep 8, 2022

Conversation

pettinarip
Copy link
Member

@pettinarip pettinarip commented Sep 5, 2022

Implement correct types for Gatsby images.

The native getImage and getSrc Gatsby functions do not play very well with the types generated by GraphQL Typegen.

The Gatsby team has improved a bit these functions but they still do not support null values.

In this PR, I've created a custom wrapper to deal with the null cases.


Most of the changes you see here are just:

  • Usage of the new getImage and getSrc functions
  • Usage of the Gatsby image interfaces where we had a type string before. These are:
    • ImageDataLike => data shape returned by the graphql query
    • IGatsbyImageData => data shape returned by the getImage function

@vercel
Copy link

vercel bot commented Sep 5, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
ethereum-org-website ❌ Failed (Inspect) Sep 6, 2022 at 11:21PM (UTC)

@github-actions github-actions bot added content 🖋️ This involves copy additions or edits review needed 👀 labels Sep 5, 2022
@gatsby-cloud
Copy link

gatsby-cloud bot commented Sep 5, 2022

Gatsby Cloud Build Report

ethereum-org-website-dev

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 16m

@@ -89,15 +89,16 @@ const ActionCard: React.FC<IProps> = ({
isRight,
isBottom = true,
}) => {
const isImageURL = typeof image === "string" && image.includes("http")
const isImageURL = typeof image === "string"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplifying this condition. Any sort of string must be passed to an html img tag.

isSvg = true
}
}
const isImgSrc = typeof image === "string"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If image is a string just pass it to the img tag since GatsbyImage can't process it anyway.

Furthermore, in all the instances where we are using ProductCard, we are not sending a string. Only Gatsby image instances.

@pettinarip pettinarip changed the title Fix Gatsby image type TS - Fix Gatsby image type Sep 6, 2022
@pettinarip pettinarip marked this pull request as ready for review September 6, 2022 22:06
@minimalsm minimalsm merged commit e6a2a79 into dev Sep 8, 2022
@minimalsm minimalsm deleted the gatsby-image-type branch September 8, 2022 16:28
@corwintines corwintines mentioned this pull request Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content 🖋️ This involves copy additions or edits
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants