Skip to content

Commit e8b9324

Browse files
authored
feat: split URL categories to featured / archive (#142)
Before Submitting This PR, Please Ensure You Have Completed The Following: 1. [ ] Are internal links to wiki documents using [relative file links](https://docusaurus.io/docs/markdown-features/links)? 2. [ ] Are all new documentation files lowercase, with dash separated names (ex. unraid-os.mdx)? 3. [ ] Are all assets (images, etc), located in an assets/ subfolder next to the .md/mdx files? 4. [ ] Have you checked to ensure there aren't other open [Pull Requests](../../../pulls) for the same update/change? 5. [ ] Is the build succeeding?
2 parents ea2b8eb + f11a482 commit e8b9324

File tree

1 file changed

+104
-31
lines changed

1 file changed

+104
-31
lines changed

src/components/ReleasesList/index.tsx

+104-31
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,75 @@ import BrowserOnly from "@docusaurus/BrowserOnly";
22

33
import React, { useEffect, useState } from "react";
44

5+
interface Release extends Object {
6+
tags: string[];
7+
version: string;
8+
date: string;
9+
basefile: string;
10+
url: string;
11+
md5: string;
12+
sha256: string;
13+
changelog_pretty: string;
14+
}
15+
16+
type ParsedReleaseObject = {
17+
featured?: { releases: Release[]; title: string; description: string };
18+
archive?: { releases: Release[]; title: string; description: string };
19+
};
20+
type Releases = Release[];
21+
522
export function ReleasesListViewer() {
6-
const [releases, setReleases] = useState([]);
23+
const [releases, setReleases] = useState<ParsedReleaseObject>({
24+
featured: {
25+
releases: [],
26+
title: "Featured",
27+
description: "Recommended Releases",
28+
},
29+
archive: {
30+
releases: [],
31+
title: "Archive",
32+
description: "Older / Non-Recommended Releases",
33+
},
34+
});
735

836
useEffect(() => {
937
const fetchData = async () => {
1038
try {
11-
const response = await fetch(
12-
"https://releases.unraid.net/json?archived=true"
39+
const response = await fetch("https://releases.unraid.net/json");
40+
const data: Release[] = await response.json();
41+
const parsedReleases = data.reduce<{
42+
featured: Release[];
43+
archive: Release[];
44+
}>(
45+
(acc, releases) => {
46+
if (releases.tags.includes("featured")) {
47+
acc.featured.push(releases);
48+
} else {
49+
acc.archive.push(releases);
50+
}
51+
return acc;
52+
},
53+
{ featured: [], archive: [] }
1354
);
14-
const data = await response.json();
15-
setReleases(data);
55+
56+
setReleases({
57+
...(parsedReleases.featured.length
58+
? {
59+
featured: {
60+
...releases.featured,
61+
releases: parsedReleases.featured,
62+
},
63+
}
64+
: {}),
65+
...(parsedReleases.archive.length
66+
? {
67+
archive: {
68+
...releases.archive,
69+
releases: parsedReleases.archive,
70+
},
71+
}
72+
: {}),
73+
});
1674
} catch (error) {
1775
console.error(error);
1876
}
@@ -22,32 +80,47 @@ export function ReleasesListViewer() {
2280
}, []);
2381

2482
return (
25-
<table>
26-
<thead>
27-
<th>Version</th>
28-
<th>Created</th>
29-
<th>Download</th>
30-
<th>Changelog</th>
31-
<th>MD5</th>
32-
</thead>
33-
<tbody>
34-
{releases.map((release) => (
35-
<tr>
36-
<td>{release.version}</td>
37-
<td>{release.date}</td>
38-
<td>
39-
<a download href={release.url}>
40-
{release.basefile}
41-
</a>
42-
</td>
43-
<td>
44-
<a href={release.changelog_pretty}>Changelog</a>
45-
</td>
46-
<td>{release.md5}</td>
47-
</tr>
48-
))}
49-
</tbody>
50-
</table>
83+
<>
84+
{Object.values(releases).map(({ title, description, releases }) => (
85+
<div
86+
key={title}
87+
style={{
88+
display: "flex",
89+
flexDirection: "column",
90+
flex: 1,
91+
}}
92+
>
93+
<h2>{title}</h2>
94+
<p>{description}</p>
95+
<table>
96+
<thead>
97+
<th>Version</th>
98+
<th>Created</th>
99+
<th>Download</th>
100+
<th>Changelog</th>
101+
<th>MD5</th>
102+
</thead>
103+
<tbody>
104+
{releases.map((release) => (
105+
<tr key={release.version}>
106+
<td>{release.version}</td>
107+
<td>{release.date}</td>
108+
<td>
109+
<a download href={release.url}>
110+
{release.basefile}
111+
</a>
112+
</td>
113+
<td>
114+
<a href={release.changelog_pretty}>Changelog</a>
115+
</td>
116+
<td>{release.md5}</td>
117+
</tr>
118+
))}
119+
</tbody>
120+
</table>
121+
</div>
122+
))}
123+
</>
51124
);
52125
}
53126

0 commit comments

Comments
 (0)