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

Making headers clickable and aligning text #151

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 32 additions & 26 deletions src/components/LatestVersion/index.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
import React, { useState, useEffect } from "react";
import Link from "@docusaurus/Link";
import moment from "moment";
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";
import styles from "../../pages/index.module.css"
Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of this looks like conflicting formatter churn. Can we either:

a. avoid committing the code style changes (I'm assuming this means disable your default formatting settings that you may have in your editor for this workspace)
b. add configuration to the project to use for formatting

I personally prefer option A, because I don't want to maintain more formatting config than I have to, but low GAFO.

import * as Arrow from "@site/static/img/arrow.svg"

interface Release {
tag_name: string;
published_at: string;
tag_name: string
published_at: string
}

interface ReleaseRemarkProps {
latestVersion: string;
latestReleaseDate: string;
latestVersion: string
latestReleaseDate: string
}

const ReleaseRemark = ({
latestVersion,
latestReleaseDate,
}: ReleaseRemarkProps) => {
const daysSinceRelease =
moment(latestReleaseDate).diff(moment(), "days") * -1;
const daysSinceRelease = moment(latestReleaseDate).diff(moment(), "days") * -1
const releaseString =
daysSinceRelease === 0
? "today"
: `${moment.duration(daysSinceRelease, "days").humanize()} ago`;
: `${moment.duration(daysSinceRelease, "days").humanize()} ago`
return (
<>
<b>{latestVersion}</b> released <b>{releaseString}</b>
</>
);
};
)
}

const LatestRelease = () => {
const [latestVersion, setLatestVersion] = useState<string>("");
const [latestReleaseDate, setLatestReleaseDate] = useState<string>("");
const [loading, setLoading] = useState(true);
const [latestVersion, setLatestVersion] = useState<string>("")
const [latestReleaseDate, setLatestReleaseDate] = useState<string>("")
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);
setLatestReleaseDate(data.published_at)
setLatestVersion(data.tag_name)
setLoading(false)
})
.catch((error) => console.error("Error fetching latest release:", error));
}, []);
.catch((error) => console.error("Error fetching latest release:", error))
}, [])

return (
<>
Expand All @@ -62,7 +61,14 @@ const LatestRelease = () => {
</Link>
) : (
<>
<h3 className={styles.notificationTitle}>Ignite</h3>
<h3 className={styles.notificationTitle}>
<Link
className={styles.notificationTitleLink}
href={`https://github.com/infinitered/ignite/releases/tag/${latestVersion}`}
>
Ignite
</Link>
</h3>
<p className={styles.notificationDate}>
<ReleaseRemark
latestVersion={latestVersion}
Expand All @@ -79,7 +85,7 @@ const LatestRelease = () => {
</>
)}
</>
);
};
)
}

export default LatestRelease;
export default LatestRelease
21 changes: 13 additions & 8 deletions src/pages/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@
}

.notificationTag {
display: flex;
flex-direction: row;
align-items: flex-start;
padding: 4px 12px;
gap: 10px;
width: 103px;
height: 29px;
display: inline-block;
padding: 0px 12px;
background: #E8C1B4;
}

.notificationTagText {
color: #692810;
font-size: 14px;
line-height: 21px;
line-height: 29px;
margin: 0px;
}

.notificationTitle {
Expand All @@ -45,6 +41,15 @@
line-height: 24px;
}

.notificationTitleLink {
color: inherit;
}

.notificationTitleLink:hover {
color: inherit;
text-decoration: underline;
}

.notificationDate {
color: #564E4A;
font-size: 16px;
Expand Down
77 changes: 42 additions & 35 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import React from "react";
import Link from "@docusaurus/Link";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
import Layout from "@theme/Layout";
import HomepageFeatures from "@site/src/components/HomepageFeatures";
import moment from "moment";
import React from "react"
import Link from "@docusaurus/Link"
import useDocusaurusContext from "@docusaurus/useDocusaurusContext"
import Layout from "@theme/Layout"
import HomepageFeatures from "@site/src/components/HomepageFeatures"
import moment from "moment"

import styles from "./index.module.css";
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";
import styles from "./index.module.css"
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");
const chefHat = require("@site/static/img/chef-hat.png");
const heroImage = require("@site/static/img/hero-graphic.svg")
const faceWinking = require("@site/static/img/face-winking.png")
const chefHat = require("@site/static/img/chef-hat.png")

const NewSection = () => {
const { snippets } = usePluginData("example-code-snippets") as {
snippets: Snippet[];
};
snippets: Snippet[]
}

const mostRecentRecipe = snippets.sort(
(a, b) =>
new Date(b.publish_date).getTime() - new Date(a.publish_date).getTime()
)[0];
)[0]

return (
<div className={styles.newSection}>
Expand All @@ -33,7 +33,14 @@ const NewSection = () => {
<div className={styles.notificationTag}>
<p className={styles.notificationTagText}>New Recipe</p>
</div>
<h3 className={styles.notificationTitle}>{mostRecentRecipe.title}</h3>
<h3 className={styles.notificationTitle}>
<Link
className={styles.notificationTitleLink}
to={`/docs/recipes/${mostRecentRecipe.doc_name.split(".")[0]}`}
>
{mostRecentRecipe.title}
</Link>
</h3>
<p className={styles.notificationDate}>
{`Published on `}
<b>
Expand All @@ -55,12 +62,12 @@ const NewSection = () => {
<LatestRelease />
</div>
</div>
);
};
)
}

const title = "Proven Recipes for your React Native apps";
const title = "Proven Recipes for your React Native apps"
const description =
"Starting from scratch doesn’t always make sense. That’s why we made the Ignite Cookbook for React Native – an easy way for developers to browse and share code snippets (or “recipes”) that actually work. ";
"Starting from scratch doesn’t always make sense. That’s why we made the Ignite Cookbook for React Native – an easy way for developers to browse and share code snippets (or “recipes”) that actually work. "

function HomepageHeader() {
return (
Expand Down Expand Up @@ -89,23 +96,23 @@ function HomepageHeader() {
</div>
</div>
</header>
);
)
}

function FreshRecipes() {
const { snippets } = usePluginData("example-code-snippets") as {
snippets: {
author: string;
publish_date: string;
title: string;
doc_name: string;
}[];
};
author: string
publish_date: string
title: string
doc_name: string
}[]
}

const mostRecentRecipes = snippets.sort(
(a, b) =>
new Date(b.publish_date).getTime() - new Date(a.publish_date).getTime()
);
)

return (
<div className={styles.freshSection}>
Expand All @@ -130,17 +137,17 @@ function FreshRecipes() {
<b>{recipe.author}</b>
</p>
</Link>
);
)
})}
<Link to="/docs/intro" className={styles.viewAllRecipes}>
View all recipes
</Link>
</div>
);
)
}

export default function Home(): JSX.Element {
const { siteConfig } = useDocusaurusContext();
const { siteConfig } = useDocusaurusContext()
return (
<Layout
title={siteConfig.title}
Expand All @@ -153,5 +160,5 @@ export default function Home(): JSX.Element {
<FreshRecipes />
</main>
</Layout>
);
)
}
Loading