-
Notifications
You must be signed in to change notification settings - Fork 0
Add image thumbnails to idea list #103
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3489322
style: add flex layout and thumbnail class to idea roll
meganrm 501488e
feat: show image thumbnail in idea list when figure is available
meganrm c91eed3
style: pill thumbnail with orange glow on idea list
meganrm b9050f5
refactor: extract FigureThumbnail component from IdeaRoll
meganrm 7ed3b01
move to stylesheet
meganrm 8e0361f
Merge branch 'main' of https://github.com/AllenCell/idea-board into f…
meganrm cd7d620
reduce hardcoded values
meganrm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import React from "react"; | ||
|
|
||
| import { GatsbyImage, IGatsbyImageData, getImage } from "gatsby-plugin-image"; | ||
|
|
||
| const { imgFill, scale } = require("../style/figure-thumbnail.module.css"); | ||
|
|
||
| interface FigureThumbnailProps { | ||
| figure: { | ||
| url?: string | null; | ||
| file?: { | ||
| childImageSharp?: { | ||
| gatsbyImageData: IGatsbyImageData; | ||
| } | null; | ||
| } | null; | ||
| }; | ||
| className?: string; | ||
| style?: React.CSSProperties; | ||
| } | ||
|
|
||
| const FigureThumbnail: React.FC<FigureThumbnailProps> = ({ | ||
| className, | ||
| figure, | ||
| style, | ||
| }) => { | ||
| const gatsbyImage = figure.file?.childImageSharp | ||
| ? getImage(figure.file.childImageSharp) | ||
| : null; | ||
|
|
||
| if (gatsbyImage) { | ||
| return ( | ||
| <GatsbyImage | ||
| image={gatsbyImage} | ||
| alt="" | ||
| className={className} | ||
| imgClassName={scale} | ||
| style={style} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| if (figure.url) { | ||
| return ( | ||
| <div className={className} style={style}> | ||
| <img src={figure.url} alt="" className={imgFill} /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return null; | ||
| }; | ||
|
|
||
| export default FigureThumbnail; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import React from "react"; | |
|
|
||
| import { Link, graphql, useStaticQuery } from "gatsby"; | ||
|
|
||
| import FigureThumbnail from "./FigureThumbnail"; | ||
| import { TagPopover } from "./TagPopover"; | ||
|
|
||
| const { | ||
|
|
@@ -11,6 +12,8 @@ const { | |
| listItem, | ||
| tagEyebrow, | ||
| tagSeparator, | ||
| textBlock, | ||
| thumbnail, | ||
| title, | ||
| } = require("../style/idea-roll.module.css"); | ||
|
|
||
|
|
@@ -24,6 +27,8 @@ interface IdeaRollProps { | |
| count?: number; | ||
| } | ||
|
|
||
| const THUMBNAIL_SIZE = { width: 88, height: 56 }; | ||
|
|
||
| const IdeaRoll = ({ count }: IdeaRollProps) => { | ||
| const queryData = useStaticQuery(graphql` | ||
| query IdeaRoll { | ||
|
|
@@ -40,6 +45,22 @@ const IdeaRoll = ({ count }: IdeaRollProps) => { | |
| type | ||
| name | ||
| } | ||
| preliminaryFindings { | ||
|
toloudis marked this conversation as resolved.
|
||
| figures { | ||
| type | ||
| url | ||
| file { | ||
| childImageSharp { | ||
| gatsbyImageData( | ||
| width: 88 | ||
| height: 56 | ||
| layout: FIXED | ||
| quality: 80 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. magic numbers? they seem to be repeated in the css also, so I wonder if they can be factored out into one place somehow. |
||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -55,40 +76,67 @@ const IdeaRoll = ({ count }: IdeaRollProps) => { | |
| return ( | ||
| <> | ||
| <ul className={container}> | ||
| {ideas.map((item) => ( | ||
| <li key={item.id} className={listItem}> | ||
| {item.tags.length > 0 && ( | ||
| <div className={tagEyebrow}> | ||
| {item.tags.map((tag, i) => ( | ||
| <React.Fragment key={tag}> | ||
| {i > 0 && ( | ||
| <span | ||
| className={tagSeparator} | ||
| aria-hidden="true" | ||
| > | ||
| · | ||
| </span> | ||
| )} | ||
| <TagPopover | ||
| tag={tag} | ||
| currentSlug={item.slug} | ||
| className={eyebrowTag} | ||
| /> | ||
| </React.Fragment> | ||
| ))} | ||
| {ideas.map((item) => { | ||
| const firstFigure = | ||
| item.preliminaryFindings?.figures?.[0] ?? null; | ||
|
|
||
| return ( | ||
| <li key={item.id} className={listItem}> | ||
| <div className={textBlock}> | ||
| {item.tags.length > 0 && ( | ||
| <div className={tagEyebrow}> | ||
| {item.tags.map((tag, i) => ( | ||
| <React.Fragment key={tag}> | ||
| {i > 0 && ( | ||
| <span | ||
| className={tagSeparator} | ||
| aria-hidden="true" | ||
| > | ||
| · | ||
| </span> | ||
| )} | ||
| <TagPopover | ||
| tag={tag} | ||
| currentSlug={item.slug} | ||
| className={eyebrowTag} | ||
| /> | ||
| </React.Fragment> | ||
| ))} | ||
| </div> | ||
| )} | ||
| <Link to={item.slug} className={title}> | ||
| {item.title} | ||
| </Link> | ||
| <div className={byline}> | ||
| by{" "} | ||
| {item.authors | ||
| .map((a) => a.name) | ||
| .join(" · ")} | ||
| {item.dataset | ||
| ? ` — ${item.dataset}` | ||
| : " — No public dataset"} | ||
| </div> | ||
| </div> | ||
| )} | ||
| <Link to={item.slug} className={title}> | ||
| {item.title} | ||
| </Link> | ||
| <div className={byline}> | ||
| by {item.authors.map((a) => a.name).join(" · ")} | ||
| {item.dataset | ||
| ? ` — ${item.dataset}` | ||
| : " — No public dataset"} | ||
| </div> | ||
| </li> | ||
| ))} | ||
|
|
||
| {firstFigure && ( | ||
| <Link | ||
| to={item.slug} | ||
| tabIndex={-1} | ||
| aria-hidden="true" | ||
| > | ||
|
meganrm marked this conversation as resolved.
|
||
| <FigureThumbnail | ||
| style={{ | ||
| width: THUMBNAIL_SIZE.width, | ||
| height: THUMBNAIL_SIZE.height, | ||
| }} | ||
| figure={firstFigure} | ||
| className={thumbnail} | ||
| /> | ||
| </Link> | ||
| )} | ||
| </li> | ||
| ); | ||
| })} | ||
| </ul> | ||
| {count !== undefined && ( | ||
| <div> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| .scale { | ||
| transform: scale(1.2); | ||
| transform-origin: center; | ||
| } | ||
|
|
||
| .imgFill { | ||
| width: 100%; | ||
| height: 100%; | ||
| object-fit: cover; | ||
| object-position: center; | ||
| display: block; | ||
| transform: scale(1.2); | ||
| transform-origin: center; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, Is there a non-sharp child image? (like a blurred thumbnail or something?)