Skip to content

Commit f087d50

Browse files
committed
fix version number
1 parent 182e286 commit f087d50

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/components/download/DownloadInfo/DownloadInfo.tsx

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ type GithubProps = {
88
repo: string;
99
};
1010

11+
type ReleaseData = {
12+
name: string;
13+
published_at: string;
14+
prerelease: boolean;
15+
};
16+
1117
const DownloadInfo = function ({ owner, repo }: GithubProps) {
1218
const [isLoading, setIsLoading] = useState(true);
1319
const [published, setPublished] = useState("");
@@ -16,22 +22,16 @@ const DownloadInfo = function ({ owner, repo }: GithubProps) {
1622
useEffect(() => {
1723
fetch(`https://api.github.com/repos/${owner}/${repo}/releases`)
1824
.then((res) =>
19-
res.json().then((val) => {
25+
res.json().then((val: ReleaseData[]) => {
2026
if (val.length) {
21-
for (let data of val) {
22-
if (!data.prerelease) {
23-
const data = val[0];
24-
clientVersion.set(data.name ? data.name.slice(1) : "");
25-
26-
// 2024-07-08T12:58:59Z -> 08.07.2024
27-
setPublished(
28-
data.published_at
29-
? data.published_at.split("T")[0].split("-").reverse().join(".")
30-
: "",
31-
);
32-
break;
33-
}
34-
}
27+
// find latest version that is not a prerelease, the api should list them in order of newest to oldest
28+
const latestVersion = val.find((data) => data.prerelease === false);
29+
clientVersion.set(latestVersion?.name ? latestVersion.name.slice(1) : "");
30+
setPublished(
31+
latestVersion?.published_at
32+
? latestVersion.published_at.split("T")[0].split("-").reverse().join(".")
33+
: "",
34+
);
3535
}
3636
setIsLoading(false);
3737
}),

0 commit comments

Comments
 (0)