generated from act-now-coalition/act-now-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
288 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,13 @@ | ||
import { Box } from "@mui/material"; | ||
|
||
import { styled } from "../../styles"; | ||
|
||
export const ratio = 16 / 9; | ||
export const width = 900; | ||
export const height = width / ratio; | ||
|
||
export const ShareImageContainer = styled(Box)` | ||
padding: ${({ theme }) => theme.spacing(4, 5)}; | ||
width: ${width}px; | ||
height: ${height}px; | ||
`; |
This file contains 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,17 @@ | ||
import React from "react"; | ||
|
||
import { ComponentMeta, ComponentStory } from "@storybook/react"; | ||
|
||
import { ShareImageHomepage } from "."; | ||
|
||
export default { | ||
title: "Components/ShareImageHomepage", | ||
component: ShareImageHomepage, | ||
} as ComponentMeta<typeof ShareImageHomepage>; | ||
|
||
const Template: ComponentStory<typeof ShareImageHomepage> = () => ( | ||
<ShareImageHomepage /> | ||
); | ||
|
||
export const Home = Template.bind({}); | ||
Home.args = {}; |
This file contains 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,31 @@ | ||
import React from "react"; | ||
|
||
import { Box, Stack, Typography } from "@mui/material"; | ||
|
||
import { MetricWorldMap } from "@actnowcoalition/actnow.js"; | ||
|
||
import { MetricId } from "../../utils/metrics"; | ||
import { regions } from "../../utils/regions"; | ||
import { ShareImageContainer } from "./ShareImage.styles"; | ||
|
||
export const ShareImageHomepage = () => ( | ||
<ShareImageContainer sx={{ background: "linear-gradient(#00bfa5, #0091ea)" }}> | ||
<Stack spacing={2} alignItems="center"> | ||
<Typography variant="h1" sx={{ mt: 0 }} color="white"> | ||
World Happiness Report 2022 | ||
</Typography> | ||
<Box | ||
sx={{ | ||
width: 700, | ||
backgroundColor: (theme) => theme.palette.common.white, | ||
borderRadius: 2, | ||
}} | ||
> | ||
<MetricWorldMap regionDB={regions} metric={MetricId.HAPPINESS} /> | ||
</Box> | ||
<Typography variant="labelLarge" color="white"> | ||
By Act Now Coalition | ||
</Typography> | ||
</Stack> | ||
</ShareImageContainer> | ||
); |
This file contains 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,18 @@ | ||
import React from "react"; | ||
|
||
import { ComponentMeta, ComponentStory } from "@storybook/react"; | ||
|
||
import { ShareImageLocation } from "."; | ||
import { regions } from "../../utils/regions"; | ||
|
||
export default { | ||
title: "Components/ShareImageLocation", | ||
component: ShareImageLocation, | ||
} as ComponentMeta<typeof ShareImageLocation>; | ||
|
||
const Template: ComponentStory<typeof ShareImageLocation> = () => ( | ||
<ShareImageLocation region={regions.findByRegionIdStrict("NOR")} /> | ||
); | ||
|
||
export const Home = Template.bind({}); | ||
Home.args = {}; |
This file contains 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,31 @@ | ||
import React from "react"; | ||
|
||
import { Box, Stack, Typography } from "@mui/material"; | ||
|
||
import { MetricWorldMap, Region } from "@actnowcoalition/actnow.js"; | ||
|
||
import { MetricId } from "../../utils/metrics"; | ||
import { regions } from "../../utils/regions"; | ||
import { ShareImageContainer } from "./ShareImage.styles"; | ||
|
||
export const ShareImageLocation = ({ region }: { region: Region }) => ( | ||
<ShareImageContainer sx={{ background: "linear-gradient(#00bfa5, #0091ea)" }}> | ||
<Stack spacing={2} alignItems="center"> | ||
<Typography variant="h1" sx={{ mt: 0 }} color="white"> | ||
{`Happiness in ${region.shortName}`} | ||
</Typography> | ||
<Box | ||
sx={{ | ||
width: 700, | ||
backgroundColor: (theme) => theme.palette.common.white, | ||
borderRadius: 2, | ||
}} | ||
> | ||
<MetricWorldMap regionDB={regions} metric={MetricId.HAPPINESS} /> | ||
</Box> | ||
<Typography variant="labelLarge" color="white"> | ||
By Act Now Coalition | ||
</Typography> | ||
</Stack> | ||
</ShareImageContainer> | ||
); |
This file contains 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,2 @@ | ||
export * from "./ShareImageHomepage"; | ||
export * from "./ShareImageLocation"; |
This file contains 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 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,34 @@ | ||
import { useRef, useState } from "react"; | ||
|
||
import { Box } from "@mui/material"; | ||
import { NextPage } from "next"; | ||
|
||
import { useMutationObserver } from "@actnowcoalition/actnow.js"; | ||
|
||
import { ScreenshotWrapper } from "components/Containers"; | ||
import { ShareImageHomepage } from "components/ShareImages"; | ||
import { searchDomForClass } from "src/utils/share-pages"; | ||
|
||
// http://localhost:3000/internal/share-image/homepage | ||
const HomeSharePage: NextPage = () => { | ||
const ref = useRef<Element>(null); | ||
|
||
const [isLoaded, setIsLoaded] = useState<boolean>(false); | ||
const handleMutations: MutationCallback = (mutations: MutationRecord[]) => { | ||
for (const mutation of mutations) { | ||
if (mutation.type === "childList") { | ||
searchDomForClass(mutation.target as Element, setIsLoaded); | ||
} | ||
} | ||
}; | ||
useMutationObserver(ref, handleMutations, { childList: true, subtree: true }); | ||
|
||
return ( | ||
<ScreenshotWrapper className="screenshot"> | ||
<Box ref={ref} className={isLoaded ? "screenshot-ready" : undefined}> | ||
<ShareImageHomepage /> | ||
</Box> | ||
</ScreenshotWrapper> | ||
); | ||
}; | ||
export default HomeSharePage; |
This file contains 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,54 @@ | ||
import { useRef, useState } from "react"; | ||
|
||
import { Box } from "@mui/material"; | ||
import isEmpty from "lodash/isEmpty"; | ||
import { NextPage } from "next"; | ||
import { useRouter } from "next/router"; | ||
|
||
import { | ||
Region, | ||
assert, | ||
useMutationObserver, | ||
} from "@actnowcoalition/actnow.js"; | ||
|
||
import { regions } from "../../../utils/regions"; | ||
import { ScreenshotWrapper } from "components/Containers"; | ||
import { ShareImageLocation } from "components/ShareImages"; | ||
import { searchDomForClass } from "src/utils/share-pages"; | ||
|
||
// http://localhost:3000/internal/share-image/location?regionId=CAN | ||
const LocationSharePage: NextPage = () => { | ||
const router = useRouter(); | ||
const ref = useRef<Element>(null); | ||
|
||
const [isLoaded, setIsLoaded] = useState<boolean>(false); | ||
const handleMutations: MutationCallback = (mutations: MutationRecord[]) => { | ||
for (const mutation of mutations) { | ||
if (mutation.type === "childList") { | ||
searchDomForClass(mutation.target as Element, setIsLoaded); | ||
} | ||
} | ||
}; | ||
useMutationObserver(ref, handleMutations, { childList: true, subtree: true }); | ||
|
||
if (isEmpty(router.query)) { | ||
return ( | ||
<span> | ||
Page loading or no query params were provided. Expects params: regionId | ||
</span> | ||
); | ||
} | ||
|
||
const { regionId } = router.query; | ||
const region = regions.findByRegionIdStrict(regionId as string); | ||
assert(region instanceof Region, `Region with ID ${regionId} not found`); | ||
|
||
return ( | ||
<ScreenshotWrapper className="screenshot"> | ||
<Box ref={ref} className={isLoaded ? "screenshot-ready" : undefined}> | ||
<ShareImageLocation region={region} /> | ||
</Box> | ||
</ScreenshotWrapper> | ||
); | ||
}; | ||
export default LocationSharePage; |
This file contains 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.
cf2c0f9
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.
Successfully deployed to the following URLs:
demo-world-happiness-report – ./
demo-world-happiness-report.vercel.app
demo-world-happiness-report-git-develop-act-now-coalition.vercel.app
demo-world-happiness-report-act-now-coalition.vercel.app