From c9be96e5dafeda8724af845592ba30340d19fb75 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Wed, 28 Feb 2024 08:18:33 -0500 Subject: [PATCH] Dynamically display ignite release versions (#135) * Add LatestRelease component and update notificationSection styles * Fix key warning in FreshRecipes component * Fix typo in YAML heading * Added comment * Refactor recipe link key in FreshRecipes component * Update LatestVersion component title * Refactor LatestRelease component to use ReleaseRemark component * Refactor releaseString logic in LatestVersion component --- docs/recipes/SampleYAMLCircleCI.md | 2 +- src/components/LatestVersion/index.tsx | 85 ++++++++++++++++++++++++++ src/pages/index.module.css | 2 + src/pages/index.tsx | 27 +------- 4 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 src/components/LatestVersion/index.tsx diff --git a/docs/recipes/SampleYAMLCircleCI.md b/docs/recipes/SampleYAMLCircleCI.md index 17e1a50f..aa878862 100644 --- a/docs/recipes/SampleYAMLCircleCI.md +++ b/docs/recipes/SampleYAMLCircleCI.md @@ -9,7 +9,7 @@ last_update: publish_date: 2022-10-09 --- -### Sampl YAML File +### Sample YAML File ```yaml # Javascript Node CircleCI 2.0 configuration file diff --git a/src/components/LatestVersion/index.tsx b/src/components/LatestVersion/index.tsx new file mode 100644 index 00000000..74d5f0d0 --- /dev/null +++ b/src/components/LatestVersion/index.tsx @@ -0,0 +1,85 @@ +import React, { useState, useEffect } from "react"; +import Link from "@docusaurus/Link"; +import moment from "moment"; + +// Bringing in the styles from the `pages/index.module.css` file to not have to duplicate the styles (nothing is new in this component) +import styles from "../../pages/index.module.css"; +import * as Arrow from "@site/static/img/arrow.svg"; + +interface Release { + tag_name: string; + published_at: string; +} + +interface ReleaseRemarkProps { + latestVersion: string; + latestReleaseDate: string; +} + +const ReleaseRemark = ({ + latestVersion, + latestReleaseDate, +}: ReleaseRemarkProps) => { + const daysSinceRelease = + moment(latestReleaseDate).diff(moment(), "days") * -1; + const releaseString = + daysSinceRelease !== 0 + ? "today" + : `${moment.duration(daysSinceRelease, "days").humanize()} ago`; + return ( + <> + {latestVersion} released {releaseString} + + ); +}; + +const LatestRelease = () => { + const [latestVersion, setLatestVersion] = useState(""); + const [latestReleaseDate, setLatestReleaseDate] = useState(""); + const [loading, setLoading] = useState(true); + + useEffect(() => { + fetch("https://api.github.com/repos/infinitered/ignite/releases/latest") + .then((response) => response.json()) + .then((data: Release) => { + setLatestReleaseDate(data.published_at); + setLatestVersion(data.tag_name); + setLoading(false); + }) + .catch((error) => console.error("Error fetching latest release:", error)); + }, []); + + return ( + <> +

Latest Ignite Release

+ {loading ? ( + + View on Github + + + ) : ( + <> +

Ignite

+

+ +

+ + View on Github + + + + )} + + ); +}; + +export default LatestRelease; diff --git a/src/pages/index.module.css b/src/pages/index.module.css index 02e619a5..29468c58 100644 --- a/src/pages/index.module.css +++ b/src/pages/index.module.css @@ -16,6 +16,8 @@ .notificationSection { margin-bottom: 20px; + min-width: 220px !important; + min-height: 130px !important; } .notificationTag { diff --git a/src/pages/index.tsx b/src/pages/index.tsx index c955d081..eefc5eb2 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -10,6 +10,7 @@ import SVGImage from "../components/SVGImage"; import { usePluginData } from "@docusaurus/useGlobalData"; import * as Arrow from "@site/static/img/arrow.svg"; import type { Snippet } from "../types"; +import LatestRelease from "../components/LatestVersion"; const heroImage = require("@site/static/img/hero-graphic.svg"); const faceWinking = require("@site/static/img/face-winking.png"); @@ -25,9 +26,6 @@ const NewSection = () => { new Date(b.publish_date).getTime() - new Date(a.publish_date).getTime() )[0]; - const igniteReleaseVersion = "v9.6.1"; - const igniteReleaseDate = moment("2024-02-21").diff(moment(), "days") * -1; - return (
{mostRecentRecipe && ( @@ -54,27 +52,7 @@ const NewSection = () => {
)}
-

Releases

-

Ignite Exp[ress]o ☕️

-

- {igniteReleaseDate > 0 ? ( - <> - {igniteReleaseVersion} released{" "} - {igniteReleaseDate} days ago - - ) : ( - <> - {igniteReleaseVersion} released today! - - )} -

- - View on Github - - +
); @@ -135,6 +113,7 @@ function FreshRecipes() { {mostRecentRecipes.slice(0, 4).map((recipe) => { return (