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

Implement basic share images #30

Merged
merged 4 commits into from
Feb 3, 2023
Merged

Implement basic share images #30

merged 4 commits into from
Feb 3, 2023

Conversation

pnavarrc
Copy link
Contributor

@pnavarrc pnavarrc commented Feb 3, 2023

Part of #28 - Implement share images for the home and location pages.

In this PR, I'm using the same share image for both pages (except for the location name) to test the sharing service first and have the setup ready. The share images look like this:

image

I also updated the MetricId enum to make it easier to pass the metric as a URL parameter, if we use it to have share images per metric.

Testing

Run the app locally and then go to:

@vercel
Copy link

vercel bot commented Feb 3, 2023

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

Name Status Preview Updated
demo-world-happiness-report ✅ Ready (Inspect) Visit Preview Feb 3, 2023 at 0:08AM (UTC)

<CssBaseline />
<Story />
</ThemeProvider>
</MetricCatalogProvider>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need the MetricCatalogProvider to make metrics available to components in Storybook (will port this to the template)

@@ -17,7 +17,8 @@
"repl": "yarn run-script scripts/repl/repl.ts",
"hello": "yarn run-script scripts/hello/index.ts",
"generate-data-snapshot": "yarn run-script scripts/data/generate-snapshot.ts",
"create-share-page": "plop share-page"
"create-share-page": "plop share-page",
"create-component": "plop component"
Copy link
Contributor

@mikelehen mikelehen Feb 3, 2023

Choose a reason for hiding this comment

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

Will we port this plop to the template?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, actually I didn't really use it, but I will test & port!

@@ -25,7 +25,7 @@ import {

import { RegionSearch } from "@actnowcoalition/actnow.js";

import { regions } from "src/utils/regions";
import { regions } from "../../utils/regions";
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should remove "baseUrl": "." from the tsconfig so you can't do this in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm actually okay with src/utils/regions, but Storybook isn't - I think I need to add src and components as aliases to the Storybook config, but didn't want to get into that on this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, cool. When I tried to do "baseUrl": "src" in act-now-packages, it broke storybook and jest as well as any projects consuming the actnow.js package. I fixed the first 2 but I think the 3rd was not fixable, so I had to revert it and now I feel like baseUrl maybe adds unnecessary complexity. But I don't feel strongly. 😁

@mikelehen
Copy link
Contributor

Can you remove "Close #28" from the PR description if this isn't actually the final PR?

}
}
};
useMutationObserver(ref, handleMutations, { childList: true, subtree: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW- Repeating all of this in every share page seems non-ideal. I'm also not entirely understanding how it works (it seems like we are waiting for "act-now-component-loaded" class and then adding a different "screenshot-ready" class; why not just have the screenshot capture use the "act-now-component-loaded" class directly? I may be missing something...)

I'll throw a topic on the standup discussion to discuss with Sean on Monday.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, maybe we can create a hook that handles all that in one go

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this got really messy and is overcomplicated for most use cases.

The problem that the mutation observer is trying to solve is the situation where you have a share page with two components that use the "act-now-component-loaded" class upon load. If one component typically loads more slowly than the other (e.g. a <MetricUsMap/> vs a <MetricValue/>), then, if we just look for the "act-now-component-loaded" class, the screenshot could be taken after the <MetricValue/> loads but while the <MetricUsMap/> is still gray/loading.

Using the mutation observer to wait until the "slow to load" component is ready sort-of resolves this (it's not a guarantee that the map will always load more slowly), but it is clunky. I think it's worth exploring ways to clean it up

Copy link
Contributor

Choose a reason for hiding this comment

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

Not 100% sure if this would work, but maybe we could have components add a act-now-component-loading class while they're loading and a act-now-component-loaded class when they're done loading. And then the screenshot capturer could look for at least one act-now-component-loaded and no act-now-component-loading elements or something.

Anyway, thanks for the details! We can discuss more at standup.

@pnavarrc pnavarrc merged commit cf2c0f9 into develop Feb 3, 2023
@pnavarrc pnavarrc deleted the pablo/28-share-images branch February 3, 2023 00:34
@smcclure17
Copy link
Contributor

smcclure17 commented Feb 3, 2023

With your new <ShareImageContainer/> component, I think we can maybe replace the <ScreenshotWrapper className="screenshot"/> element with just a normal <Box className="screenshot"/>.

Right now there's a bit of whitespace in the screenshots (example) because the <ScreenshotWrapper/> component has a fixed width of 1200px, which leaves some empty space around the share component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants