Skip to content

Commit

Permalink
Merge branch 'main' into chore/a11y/blog-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
georgiee authored Jan 16, 2024
2 parents fe77cad + d1ad0a1 commit c3055a8
Show file tree
Hide file tree
Showing 9 changed files with 1,139 additions and 888 deletions.
86 changes: 43 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,42 @@
"@reach/accordion": "^0.18.0",
"@reach/listbox": "^0.18.0",
"@reach/tabs": "^0.18.0",
"@slack/web-api": "^6.8.1",
"@slack/web-api": "^6.11.2",
"@svgr/webpack": "^8.0.1",
"@types/leaflet": "^1.9.8",
"axios": "^1.4.0",
"axios": "^1.6.5",
"babel-plugin-styled-components": "^2.1.3",
"canvas": "^2.11.2",
"date-fns": "^2.30.0",
"fast-xml-parser": "^4.2.2",
"gatsby": "^5.12.12",
"date-fns": "^3.2.0",
"fast-xml-parser": "^4.3.3",
"gatsby": "^5.13.1",
"gatsby-background-image": "^1.6.0",
"gatsby-plugin-canonical-urls": "^5.10.0",
"gatsby-plugin-catch-links": "^5.10.0",
"gatsby-plugin-feed": "^5.12.3",
"gatsby-plugin-gatsby-cloud": "^5.12.2",
"gatsby-plugin-image": "^3.12.3",
"gatsby-plugin-manifest": "^5.12.3",
"gatsby-plugin-canonical-urls": "^5.13.0",
"gatsby-plugin-catch-links": "^5.13.0",
"gatsby-plugin-feed": "^5.13.0",
"gatsby-plugin-gatsby-cloud": "^5.13.0",
"gatsby-plugin-image": "^3.13.0",
"gatsby-plugin-manifest": "^5.13.0",
"gatsby-plugin-react-i18next": "^3.0.1",
"gatsby-plugin-readingtime": "^3.0.1",
"gatsby-plugin-readingtime": "^3.0.2",
"gatsby-plugin-robots-txt": "^1.8.0",
"gatsby-plugin-sass": "^6.12.3",
"gatsby-plugin-sharp": "^5.12.3",
"gatsby-plugin-sitemap": "^6.12.3",
"gatsby-plugin-sass": "^6.13.0",
"gatsby-plugin-sharp": "^5.13.0",
"gatsby-plugin-sitemap": "^6.13.0",
"gatsby-plugin-smoothscroll": "^1.2.0",
"gatsby-plugin-styled-components": "^6.10.0",
"gatsby-plugin-styled-components": "^6.13.0",
"gatsby-plugin-svgr": "^3.0.0-beta.0",
"gatsby-remark-copy-linked-files": "^6.10.0",
"gatsby-remark-copy-linked-files": "^6.13.0",
"gatsby-remark-external-links": "^0.0.4",
"gatsby-remark-images": "^7.12.3",
"gatsby-remark-prismjs": "^7.10.0",
"gatsby-source-contentful": "^8.12.5",
"gatsby-source-filesystem": "^5.12.1",
"gatsby-transformer-json": "^5.10.0",
"gatsby-transformer-remark": "^6.12.3",
"gatsby-transformer-sharp": "^5.12.3",
"gatsby-remark-images": "^7.13.0",
"gatsby-remark-prismjs": "^7.13.0",
"gatsby-source-contentful": "^8.13.0",
"gatsby-source-filesystem": "^5.13.0",
"gatsby-transformer-json": "^5.13.0",
"gatsby-transformer-remark": "^6.13.0",
"gatsby-transformer-sharp": "^5.13.0",
"html-entities": "^2.3.2",
"i18next": "^23.7.8",
"i18next": "^23.7.16",
"leaflet": "^1.9.4",
"leaflet-gesture-handling": "^1.2.2",
"modern-normalize": "^2.0.0",
Expand All @@ -77,42 +77,42 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.49.0",
"react-i18next": "^13.5.0",
"react-hook-form": "^7.49.3",
"react-i18next": "^14.0.0",
"react-leaflet": "^4.2.1",
"react-medium-image-zoom": "^5.1.6",
"react-medium-image-zoom": "^5.1.10",
"react-share": "^5.0.3",
"react-spring": "^9.7.3",
"react-use": "^17.4.2",
"react-use": "^17.4.3",
"rehype-react": "^7.2.0",
"sass": "^1.62.1",
"sass": "^1.69.7",
"schema-dts": "^1.1.2",
"sharp": "^0.33.0",
"sharp": "^0.33.2",
"showdown": "^2.1.0",
"slugify": "^1.6.6",
"striptags": "^3.2.0",
"styled-components": "^6.1.1",
"stylis": "^4.0.0",
"styled-components": "^6.1.8",
"stylis": "^4.3.1",
"unified": "^10.1.1",
"util": "^0.12.5",
"webpack": "^5.84.1",
"what-input": "^5.2.12"
},
"devDependencies": {
"@babel/core": "^7.23.5",
"@testing-library/jest-dom": "^6.1.5",
"@babel/core": "^7.23.7",
"@testing-library/jest-dom": "^6.2.0",
"@testing-library/react": "^14.0.0",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.4",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@types/node": "^20.11.0",
"@types/react": "^18.2.47",
"@types/react-dom": "^18.2.18",
"@types/react-syntax-highlighter": "^15.5.11",
"@types/showdown": "^2.0.6",
"@types/styled-components": "^5.1.34",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"babel-loader": "^9.1.2",
"eslint": "^8.55.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-jest-dom": "^5.1.0",
Expand All @@ -122,9 +122,9 @@
"identity-obj-proxy": "^3.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jsdom": "^23.0.1",
"jsdom": "^23.2.0",
"lint-staged": "^15.2.0",
"prettier": "^3.1.1",
"prettier": "^3.2.2",
"serve": "^14.2.0",
"ts-jest": "^29.1.0",
"typescript": "^5.3.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export const getSunlightPercentage = (
sunriseTime: number,
sunsetTime: number,
time: number,
) => {
const totalDaylightMinutes = sunsetTime - sunriseTime;
if (totalDaylightMinutes <= 0) {
return 20;
}
const currentMinutes = time - sunriseTime;
const sunlightPercentage = (currentMinutes / totalDaylightMinutes) * 100;

if (sunlightPercentage < 0) {
return 0;
}
if (sunlightPercentage > 100) {
return 100;
}
return Math.round(sunlightPercentage);
};

export const getNighttimePercentage = (
sunriseTime: number,
sunsetTime: number,
time: number,
) => {
const totalDaylightMinutes = sunsetTime - sunriseTime;
const totalNighttimeMinutes = 86400000 - totalDaylightMinutes;
if (totalNighttimeMinutes <= 0) {
return 0;
}
const currentMinutes = time - sunsetTime;
const nighttimePercentage = (currentMinutes / totalNighttimeMinutes) * 100;

if (nighttimePercentage < 0) {
return 0;
}
if (nighttimePercentage > 100) {
return 100;
}
return Math.round(nighttimePercentage);
};
97 changes: 97 additions & 0 deletions src/components/content/heroes/aurora/weather-easter-egg/moon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import styled from 'styled-components';
import React, { useEffect, useState } from 'react';

interface MoonProps {
nightPercentage: number;
}

const generateStars = (starCount: number) => {
const stars: React.JSX.Element[] = [];

for (let i = 0; i < starCount; i++) {
stars.push(
<StarsDiv x={Math.random() * 120 - 10} y={Math.random() * 120 - 10} />,
);
}

return stars;
};

const BackgroundDiv = styled.div<{ nightPercentage: number }>`
position: absolute;
background: #000000;
width: 100%;
height: 100%;
opacity: ${(props) =>
props.nightPercentage === 0 || props.nightPercentage === 100 ? '0' : '1'};
`;

const StarsDiv = styled.div<{ x: number; y: number }>`
position: absolute;
width: 3px;
height: 3px;
top: ${(props) => props.y}%;
left: ${(props) => props.x}%;
border-radius: 100%;
background: #ffffff;
`;

const MoonDiv = styled.div<{ nightPercentage: number }>`
position: absolute;
width: 100px;
height: 100px;
opacity: ${(props) =>
props.nightPercentage === 0 || props.nightPercentage === 100 ? '0' : '1'};
background: #ffffff;
left: calc(${(props) => props.nightPercentage}% - 50px);
bottom: calc(
${(props) =>
(1 / 125) *
(-(props.nightPercentage - 50) * (props.nightPercentage - 50)) +
70}%
// parabola formula to get the moon to move in a parabola
);
border-radius: 50%;
filter: blur(5px);
`;

const ParallaxDiv = styled.div<{ x: number; y: number }>`
position: absolute;
width: 100%;
height: 100%;
transform: translate(
${(props) => -props.x * 0.09}px,
${(props) => -props.y * 0.09}px
);
`;

export const Moon = ({ nightPercentage }: MoonProps) => {
const [mousePos, setMousePos] = useState({ x: 0, y: 0 });
const [stars, setStars] = useState<React.JSX.Element[]>([]);

useEffect(() => {
const handleMouseMove = (event) => {
setMousePos({ x: event.clientX, y: event.clientY });
};

window.addEventListener('mousemove', handleMouseMove);

return () => {
window.removeEventListener('mousemove', handleMouseMove);
};
}, []);

useEffect(() => {
setStars(generateStars(120));
}, []);

return (
<>
<BackgroundDiv nightPercentage={nightPercentage} />
<ParallaxDiv x={mousePos.x} y={mousePos.y}>
{nightPercentage === 0 || nightPercentage === 100 ? '' : stars}
</ParallaxDiv>
<MoonDiv nightPercentage={nightPercentage} />
</>
);
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSunlightPercentage } from './sun-percentage-calculator';
import { getSunlightPercentage } from './daylight-percentage-calculator';

describe('getSunlightPercentage', () => {
const sunriseTime = new Date('2023-07-14T06:00:00Z').getTime();
Expand Down
Loading

0 comments on commit c3055a8

Please sign in to comment.