Load an Info
's Website
separately from the Info
itself
Makes it so: - An `Info`'s `Website` doesn't need to wait for other `Website`s of that same `Info` to load to show up - An `Info`s `Website` not working won't prevent other `Website`s of that same `Info` from showing up - Code is more split and organized Furthermore, the token for the osu! API is now stored, and used for ALL osu! requests for 24 hours instead of being revoked Overall, it's a lot of future-proofing so things on working even if I'm no longer there to maintain them Also so `Info`s can be added, changed, and removed more easily
This commit is contained in:
parent
dec30acf14
commit
719672ffa0
45 changed files with 1125 additions and 759 deletions
65
src/components/Info/Coding/GitHub.tsx
Normal file
65
src/components/Info/Coding/GitHub.tsx
Normal file
|
@ -0,0 +1,65 @@
|
|||
import React, {useState, useEffect} from "react";
|
||||
import Website from "../../Website.js";
|
||||
|
||||
export type GithubInfo = {
|
||||
public?: {
|
||||
repo: string;
|
||||
date: string;
|
||||
};
|
||||
private?: {
|
||||
date: string;
|
||||
};
|
||||
};
|
||||
|
||||
export default function GitHub() {
|
||||
const [github, setGithub]: [GithubInfo, React.Dispatch<React.SetStateAction<GithubInfo>>] = useState({});
|
||||
const [elements, setElements] = useState([] as React.JSX.Element[]);
|
||||
const [error, setError] = useState(false);
|
||||
|
||||
const getGithub = async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
setGithub(await fetch("/.netlify/functions/github").then(async r => r.json()));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getGithub().catch(() => {
|
||||
setError(true);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (github.private ?? github.public) {
|
||||
try {
|
||||
const elms: React.JSX.Element[] = [];
|
||||
|
||||
if (github.private) {
|
||||
elms.push(
|
||||
<p key={"github-date-private"} className={github.public ? "mb-2" : ""}>Latest <strong>private</strong> push: <strong>{github.private.date}</strong></p>,
|
||||
);
|
||||
}
|
||||
|
||||
if (github.public) {
|
||||
elms.push(
|
||||
<p key={"github-date-public"}>Latest <strong>public</strong> push: <strong>{github.public.date} on {github.public.repo}</strong></p>,
|
||||
);
|
||||
elms.push(
|
||||
<a key={"github-link"} className="button-link" href={`https://github.com/${github.public.repo}`} target="_blank" rel="noreferrer">Repo Link</a>,
|
||||
);
|
||||
}
|
||||
|
||||
setElements(elms);
|
||||
} catch {
|
||||
setError(true);
|
||||
}
|
||||
}
|
||||
}, [github]);
|
||||
|
||||
return (
|
||||
<Website
|
||||
name="GitHub"
|
||||
link="https://github.com/TTTaevas"
|
||||
elements={elements}
|
||||
error={error}
|
||||
/>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue