From cc44f6c5d223b12bf32ae7cc52fbfecc18ead03b Mon Sep 17 00:00:00 2001 From: Lukas Pistrol Date: Mon, 27 Feb 2023 22:43:38 +0100 Subject: [PATCH 1/5] add hook with gh api call for getting vers number --- .../pages/home/sections/HeroSection.jsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/components/pages/home/sections/HeroSection.jsx b/components/pages/home/sections/HeroSection.jsx index 812bc0f..2a38006 100644 --- a/components/pages/home/sections/HeroSection.jsx +++ b/components/pages/home/sections/HeroSection.jsx @@ -6,6 +6,7 @@ import Typography from '@/components/common/Typography'; import { Row, Column, Section, Stack } from '@/components/common/layout'; import HeroImage from '../HeroImage'; import Button from '../../../common/Button'; +import { useState, useEffect } from 'react'; const ProductIconWrap = styled.div` width: 128px; @@ -14,6 +15,22 @@ const ProductIconWrap = styled.div` `; const HeroSection = () => { + + const [data, setData] = useState(null) + const [isLoading, setLoading] = useState(false) + const versionNumber = data?.name ?? 'Loading...' + + useEffect(() => { + setLoading(true) + fetch('https://api.github.com/repos/CodeEditApp/CodeEdit/releases/latest') + .then((res) => res.json()) + .then((data) => { + setData(data) + setLoading(false) + }) + }, []) + + return ( { CodeEdit is an exciting new code editor written entirely and unapologetically for macOS. Develop any project using any language at speeds like never before with increased efficiency and reliability in an editor that feels right at home on your Mac. - 0.0.1-alpha | macOS 12+ + { versionNumber } | macOS 13+ From f7a6dd487e9fd74263a2362c1c5f63e9b1ad9b56 Mon Sep 17 00:00:00 2001 From: Lukas Pistrol Date: Mon, 27 Feb 2023 22:46:29 +0100 Subject: [PATCH 2/5] minor adjustments --- components/pages/home/sections/HeroSection.jsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/components/pages/home/sections/HeroSection.jsx b/components/pages/home/sections/HeroSection.jsx index 2a38006..7ef6930 100644 --- a/components/pages/home/sections/HeroSection.jsx +++ b/components/pages/home/sections/HeroSection.jsx @@ -17,16 +17,13 @@ const ProductIconWrap = styled.div` const HeroSection = () => { const [data, setData] = useState(null) - const [isLoading, setLoading] = useState(false) const versionNumber = data?.name ?? 'Loading...' useEffect(() => { - setLoading(true) fetch('https://api.github.com/repos/CodeEditApp/CodeEdit/releases/latest') .then((res) => res.json()) .then((data) => { setData(data) - setLoading(false) }) }, []) From 29fa810cb90732cb971e7f0d90c2271f61d02721 Mon Sep 17 00:00:00 2001 From: Lukas Pistrol Date: Mon, 27 Feb 2023 22:50:15 +0100 Subject: [PATCH 3/5] remove whitespace --- components/pages/home/sections/HeroSection.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/components/pages/home/sections/HeroSection.jsx b/components/pages/home/sections/HeroSection.jsx index 7ef6930..a1978fd 100644 --- a/components/pages/home/sections/HeroSection.jsx +++ b/components/pages/home/sections/HeroSection.jsx @@ -27,7 +27,6 @@ const HeroSection = () => { }) }, []) - return ( Date: Mon, 27 Feb 2023 23:10:17 +0100 Subject: [PATCH 4/5] refactor hook to `hooks` folder --- components/pages/home/sections/HeroSection.jsx | 13 ++----------- hooks/useLatestVersionNumber.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 hooks/useLatestVersionNumber.js diff --git a/components/pages/home/sections/HeroSection.jsx b/components/pages/home/sections/HeroSection.jsx index a1978fd..63f7b6d 100644 --- a/components/pages/home/sections/HeroSection.jsx +++ b/components/pages/home/sections/HeroSection.jsx @@ -6,7 +6,7 @@ import Typography from '@/components/common/Typography'; import { Row, Column, Section, Stack } from '@/components/common/layout'; import HeroImage from '../HeroImage'; import Button from '../../../common/Button'; -import { useState, useEffect } from 'react'; +import useLatestVersionNumber from '@/hooks/useLatestVersionNumber'; const ProductIconWrap = styled.div` width: 128px; @@ -16,16 +16,7 @@ const ProductIconWrap = styled.div` const HeroSection = () => { - const [data, setData] = useState(null) - const versionNumber = data?.name ?? 'Loading...' - - useEffect(() => { - fetch('https://api.github.com/repos/CodeEditApp/CodeEdit/releases/latest') - .then((res) => res.json()) - .then((data) => { - setData(data) - }) - }, []) + const versionNumber = useLatestVersionNumber(); return ( { + const [versionNumber, setVersionNumber] = useState(); + + useEffect(() => { + fetch('https://api.github.com/repos/CodeEditApp/CodeEdit/releases/latest') + .then((res) => res.json()) + .then((data) => { + setVersionNumber(data.name) + }) + }, []) + + return versionNumber ?? 'Loading...'; +}; + +export default useLatestVersionNumber; From fe3aa5956e212cea6a72a877beb969cb61c1277d Mon Sep 17 00:00:00 2001 From: Lukas Pistrol Date: Tue, 28 Feb 2023 10:07:51 +0100 Subject: [PATCH 5/5] use ISR for getting the version tag --- components/pages/home/index.js | 4 ++-- .../pages/home/sections/HeroSection.jsx | 5 +---- hooks/useLatestVersionNumber.js | 17 ---------------- pages/index.js | 20 ++++++++++++++++++- 4 files changed, 22 insertions(+), 24 deletions(-) delete mode 100644 hooks/useLatestVersionNumber.js diff --git a/components/pages/home/index.js b/components/pages/home/index.js index f070160..de1824a 100644 --- a/components/pages/home/index.js +++ b/components/pages/home/index.js @@ -12,13 +12,13 @@ import CtaSection from './sections/CtaSection'; import SampleStorySection from './sections/SampleStorySection'; import links from '@/data/links'; -export default function HomePage() { +export default function HomePage({ versionNumber }) { return (
window.open(links.githubProject)}> CodeEdit is currently in development. Check out the roadmap. - + {/* */} {/* */} diff --git a/components/pages/home/sections/HeroSection.jsx b/components/pages/home/sections/HeroSection.jsx index 63f7b6d..22f4431 100644 --- a/components/pages/home/sections/HeroSection.jsx +++ b/components/pages/home/sections/HeroSection.jsx @@ -6,7 +6,6 @@ import Typography from '@/components/common/Typography'; import { Row, Column, Section, Stack } from '@/components/common/layout'; import HeroImage from '../HeroImage'; import Button from '../../../common/Button'; -import useLatestVersionNumber from '@/hooks/useLatestVersionNumber'; const ProductIconWrap = styled.div` width: 128px; @@ -14,9 +13,7 @@ const ProductIconWrap = styled.div` margin-right: auto; `; -const HeroSection = () => { - - const versionNumber = useLatestVersionNumber(); +const HeroSection = ({versionNumber}) => { return ( { - const [versionNumber, setVersionNumber] = useState(); - - useEffect(() => { - fetch('https://api.github.com/repos/CodeEditApp/CodeEdit/releases/latest') - .then((res) => res.json()) - .then((data) => { - setVersionNumber(data.name) - }) - }, []) - - return versionNumber ?? 'Loading...'; -}; - -export default useLatestVersionNumber; diff --git a/pages/index.js b/pages/index.js index 44d9018..d8e8212 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1 +1,19 @@ -export { default } from '@/components/pages/home'; +import HomePage from '@/components/pages/home'; + +export default function Home(props) { + return ( + + ); +} + +export async function getStaticProps() { + const res = await fetch('https://api.github.com/repos/CodeEditApp/CodeEdit/releases/latest'); + const data = await res.json(); + + return { + props: { + versionNumber: data.tag_name, + }, + revalidate: 60 * 60 * 24, // 24 hours + }; +}