|
| 1 | +import React, {useEffect, useState} from "react" |
| 2 | +import axios from "axios" |
| 3 | +import ReactMarkdown from "react-markdown" |
| 4 | +import {PageBase} from "web/components/page-base" |
| 5 | +import {SEO} from "web/components/SEO" |
| 6 | +import {Col} from "web/components/layout/col" |
| 7 | +import {Title} from "web/components/widgets/title" |
| 8 | +import Link from "next/link" |
| 9 | +import {CompassLoadingIndicator} from "web/components/widgets/loading-indicator" |
| 10 | +import {githubRepoSlug} from "common/constants"; |
| 11 | + |
| 12 | +type Release = { |
| 13 | + id: number |
| 14 | + name: string |
| 15 | + tag_name: string |
| 16 | + body: string |
| 17 | + published_at: string |
| 18 | + html_url: string |
| 19 | +} |
| 20 | + |
| 21 | +export default function WhatsNew() { |
| 22 | + const [releases, setReleases] = useState([]) |
| 23 | + const [loading, setLoading] = useState(true) |
| 24 | + const [error, setError] = useState<string | null>(null) |
| 25 | + |
| 26 | + useEffect(() => { |
| 27 | + async function fetchReleases() { |
| 28 | + try { |
| 29 | + const response = await axios.get( |
| 30 | + `https://api.github.com/repos/${githubRepoSlug}/releases`, |
| 31 | + { |
| 32 | + headers: { |
| 33 | + // Optional: if hitting rate limits, use a GitHub token |
| 34 | + // Authorization: `token ${process.env.REACT_APP_GITHUB_TOKEN}` |
| 35 | + }, |
| 36 | + } |
| 37 | + ) |
| 38 | + setReleases(response.data) |
| 39 | + } catch (err) { |
| 40 | + setError("Failed to fetch releases") |
| 41 | + } finally { |
| 42 | + setLoading(false) |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + fetchReleases() |
| 47 | + }, []) |
| 48 | + |
| 49 | + return ( |
| 50 | + <PageBase trackPageView={'news'} className={'mx-4'}> |
| 51 | + <SEO |
| 52 | + title={"What's new"} |
| 53 | + description={'All news and code updates'} |
| 54 | + url={`/news`} |
| 55 | + /> |
| 56 | + <Title className="text-3xl">What's New</Title> |
| 57 | + {loading ? <CompassLoadingIndicator/> : |
| 58 | + error ? <p>{error}</p> : |
| 59 | + <Col className="max-w-3xl mx-auto py-10 px-4 custom-link"> |
| 60 | + {releases.map((release: Release) => ( |
| 61 | + <div key={release.id} className="mb-10 border-b pb-6"> |
| 62 | + <div className="flex justify-between items-center"> |
| 63 | + <h2 className="text-xl font-semibold">{release.name || release.tag_name}</h2> |
| 64 | + <span className="text-sm text-gray-500"> |
| 65 | + {new Date(release.published_at).toLocaleDateString()} |
| 66 | + </span> |
| 67 | + </div> |
| 68 | + <div className="mt-4 prose text-ink-1000"> |
| 69 | + <ReactMarkdown>{release.body || "_No release notes provided._"}</ReactMarkdown> |
| 70 | + </div> |
| 71 | + <Link href={release.html_url}>View on GitHub</Link> |
| 72 | + </div> |
| 73 | + ))} |
| 74 | + </Col> |
| 75 | + } |
| 76 | + </PageBase> |
| 77 | + ) |
| 78 | +} |
0 commit comments